<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>db.copy - GRASS GIS manual</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="grassdocs.css" type="text/css"> </head> <body bgcolor="white"> <div id="container"> <a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a> <hr class="header"> <h2>NAME</h2> <em><b>db.copy</b></em> - Copy a table.<BR> Either 'from_table' (optionally with 'where') can be used or 'select' option, but not 'from_table' and 'select' at the same time. <h2>KEYWORDS</h2> <a href="database.html">database</a>, <a href="topic_attribute_table.html">attribute table</a>, <a href="keywords.html#SQL">SQL</a> <h2>SYNOPSIS</h2> <div id="name"><b>db.copy</b><br></div> <b>db.copy --help</b><br> <div id="synopsis"><b>db.copy</b> [<b>from_driver</b>=<em>name</em>] [<b>from_database</b>=<em>name</em>] [<b>from_table</b>=<em>name</em>] [<b>to_driver</b>=<em>name</em>] [<b>to_database</b>=<em>name</em>] <b>to_table</b>=<em>name</em> [<b>where</b>=<em>sql_query</em>] [<b>select</b>=<em>string</em>] [--<b>overwrite</b>] [--<b>help</b>] [--<b>verbose</b>] [--<b>quiet</b>] [--<b>ui</b>] </div> <div id="flags"> <h3>Flags:</h3> <dl> <dt><b>--overwrite</b></dt> <dd>Allow output files to overwrite existing files</dd> <dt><b>--help</b></dt> <dd>Print usage summary</dd> <dt><b>--verbose</b></dt> <dd>Verbose module output</dd> <dt><b>--quiet</b></dt> <dd>Quiet module output</dd> <dt><b>--ui</b></dt> <dd>Force launching GUI dialog</dd> </dl> </div> <div id="parameters"> <h3>Parameters:</h3> <dl> <dt><b>from_driver</b>=<em>name</em></dt> <dd>Input driver name</dd> <dd>Options: <em>dbf, odbc, ogr, pg, sqlite</em></dd> <dd>Default: <em>sqlite</em></dd> <dt><b>from_database</b>=<em>name</em></dt> <dd>Input database name</dd> <dd>Default: <em>$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db</em></dd> <dt><b>from_table</b>=<em>name</em></dt> <dd>Input table name (only, if 'select' is not used)</dd> <dt><b>to_driver</b>=<em>name</em></dt> <dd>Output driver name</dd> <dd>Options: <em>dbf, odbc, ogr, pg, sqlite</em></dd> <dd>Default: <em>sqlite</em></dd> <dt><b>to_database</b>=<em>name</em></dt> <dd>Output database name</dd> <dd>Default: <em>$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db</em></dd> <dt><b>to_table</b>=<em>name</em> <b>[required]</b></dt> <dd>Output table name</dd> <dt><b>where</b>=<em>sql_query</em></dt> <dd>WHERE conditions of SQL statement without 'where' keyword</dd> <dd>Example: income < 1000 and population >= 10000</dd> <dt><b>select</b>=<em>string</em></dt> <dd>Full select statement (only, if 'from_table' and 'where' is not used)</dd> <dd>E.g.: SELECT dedek FROM starobince WHERE obec = 'Frimburg'</dd> </dl> </div> <div class="toc"> <h4 class="toc">Table of contents</h4> <ul class="toc"> <li class="toc"><a href="#description" class="toc">DESCRIPTION</a></li> <li class="toc"><a href="#notes" class="toc">NOTES</a></li> <li class="toc"><a href="#examples" class="toc">EXAMPLES</a> <ul class="toc"> <li class="toc"><a href="#from-dbf-to-postgresql" class="toc">From DBF to PostgreSQL</a></li> <li class="toc"><a href="#from-postgresql-to-dbf" class="toc">From PostgreSQL to DBF</a></li> <li class="toc"><a href="#from-postgresql-to-postgresql-with-condition" class="toc">From PostgreSQL to PostgreSQL with condition</a></li> <li class="toc"><a href="#from-dbf-to-sqlite" class="toc">From DBF to SQLite</a></li> <li class="toc"><a href="#from-sqlite-to-dbf" class="toc">From SQLite to DBF</a></li> </ul></li> <li class="toc"><a href="#see-also" class="toc">SEE ALSO</a></li> <li class="toc"><a href="#author" class="toc">AUTHOR</a></li> </ul> </div> <h2><a name="description">DESCRIPTION</a></h2> <em>db.copy</em> allows the user to copy a table between two databases. Databases can be connected through different drivers (see examples below). <h2><a name="notes">NOTES</a></h2> Attribute tables can be copied using <em>db.copy</em> and, when to be associated to a vector map, assigned to the map with <em><a href="v.db.connect.html">v.db.connect</a></em>. Current connection settings are saved in the file <em>$LOCATION/vector_map/dbln</em>. <h2><a name="examples">EXAMPLES</a></h2> <h3><a name="from-dbf-to-postgresql">From DBF to PostgreSQL</a></h3> <em>Storing table 'geonames.dbf' (in current directory) into PostgreSQL through ODBC:</em><br> <div class="code"><pre> db.copy from_driver=dbf from_database='$GISDBASE/$LOCATION_NAME/PERMANENT/dbf' \ from_table=geonames to_driver=pg to_database="host=pgserver,dbname=testdb" \ to_table=geonames </pre></div> <h3><a name="from-postgresql-to-dbf">From PostgreSQL to DBF</a></h3> <div class="code"><pre> db.copy from_driver=pg from_database="host=pgserver.example.org,dbname=testdb" \ from_table=origtable to_driver=dbf \ to_database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf' to_table=origtable </pre></div> <h3><a name="from-postgresql-to-postgresql-with-condition">From PostgreSQL to PostgreSQL with condition</a></h3> <div class="code"><pre> db.copy from_driver=pg from_database="host=localhost,dbname=testdb" \ from_table=geonames to_driver=pg to_database="host=localhost,dbname=testdb" \ to_table=selection where="cat < 500" </pre></div> <h3><a name="from-dbf-to-sqlite">From DBF to SQLite</a></h3> <div class="code"><pre> db.copy from_driver=dbf from_database='$GISDBASE/$LOCATION_NAME/PERMANENT/dbf' \ from_table=geonames_features to_driver=sqlite \ to_database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db' to_table=geonames_features # convenient viewer: sqlitebrowser $HOME/grassdata/nc_spm_08/user1/sqlite/sqlite.db </pre></div> <h3><a name="from-sqlite-to-dbf">From SQLite to DBF</a></h3> <div class="code"><pre> db.copy from_driver=sqlite from_database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db' \ from_table=ammprv to_driver=dbf to_database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/' \ to_table=ammprv </pre></div> <h2><a name="see-also">SEE ALSO</a></h2> <em> <a href="db.connect.html">db.connect</a>, <a href="db.drivers.html">db.drivers</a>, <a href="db.login.html">db.login</a>, <a href="v.db.connect.html">v.db.connect</a>, <a href="v.clean.html">v.clean</a> </em> <p> <a href="sql.html">GRASS SQL interface</a> <h2><a name="author">AUTHOR</a></h2> Radim Blazek, ITC-irst, Trento, Italy <!-- <p> <i>Last changed: $Date$</i> --><h2>SOURCE CODE</h2> <p>Available at: <a href="https://github.com/OSGeo/grass/tree/master/db/db.copy">db.copy source code</a> (<a href="https://github.com/OSGeo/grass/commits/master/db/db.copy">history</a>)</p> <hr class="header"> <p> <a href="index.html">Main index</a> | <a href="database.html">Database index</a> | <a href="topics.html">Topics index</a> | <a href="keywords.html">Keywords index</a> | <a href="graphical_index.html">Graphical index</a> | <a href="full_index.html">Full index</a> </p> <p> © 2003-2020 <a href="http://grass.osgeo.org">GRASS Development Team</a>, GRASS GIS 7.8.3 Reference Manual </p> </div> </body> </html>