Import data.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 18 Dec 2018 13:06:21 +0200
changeset 2305 2d52dea2eee3
parent 2304 a2b7bf3976b5
child 2306 5892d69ad3ed
Import data.
postgres.rst
--- a/postgres.rst	Tue Dec 18 13:06:09 2018 +0200
+++ b/postgres.rst	Tue Dec 18 13:06:21 2018 +0200
@@ -14,8 +14,8 @@
   $ sudo apt-get install postgresql postgresql-client
   $ sudo su - postgres
   % psql
-  postgres=# CREATE USER "mypguser" WITH PASSWORD 'mypguserpass';
-  postgres=# CREATE DATABASE "mypgdatabase" OWNER "mypguser";
+  postgres=# CREATE USER myuser WITH PASSWORD 'mypass';
+  postgres=# CREATE DATABASE mydb OWNER myuser;
   postgres=# \q
 
 Connect as user ``mypguser`` to new database::
@@ -192,3 +192,13 @@
 
   \copy (SELECT * FROM foo) TO '/tmp/my.csv' WITH CSV
 
+Import data
+===========
+
+Import CSV file::
+
+  \copy tbl_name from 'my.csv' csv;
+  \copy tbl_name from 'my.csv' delimiter ':' csv;
+
+  $ psql -U $USER -h $HOST $DB -c "\\copy tbl_name from 'my.csv' csv"
+