db.copy.html 7.01 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
1 2 3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
xuebingbing's avatar
xuebingbing committed
4
<title>db.copy - GRASS GIS manual</title>
xuebingbing's avatar
xuebingbing committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
<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>&nbsp;<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 &lt; 1000 and population &gt;= 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 &lt; 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>
xuebingbing's avatar
xuebingbing committed
191
&copy; 2003-2020
xuebingbing's avatar
xuebingbing committed
192
<a href="http://grass.osgeo.org">GRASS Development Team</a>,
xuebingbing's avatar
xuebingbing committed
193
GRASS GIS 7.8.3 Reference Manual
xuebingbing's avatar
xuebingbing committed
194 195 196 197 198
</p>

</div>
</body>
</html>