changeset 2507:8e8c8adde585

Copy tables.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Thu, 22 Apr 2021 10:57:04 +0300
parents 04649fd8a394
children fe9788ce44ba
files postgres.rst
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/postgres.rst	Fri Apr 16 00:11:21 2021 +0300
+++ b/postgres.rst	Thu Apr 22 10:57:04 2021 +0300
@@ -596,6 +596,26 @@
 
   $ psql -U $USER -h $HOST $DB -c "\\copy tbl_name from 'my.csv' csv"
 
+Copy tables
+===========
+
+Create table *with* data copying using another table (no constraints & indices are recreated,
+including PK)::
+
+  CREATE TABLE mycopy AS TABLE myorig;
+
+Create table *without* data copying using another table::
+
+  CREATE TABLE mycopy AS TABLE myorig WITH NO DATA;
+
+Create table from select and copy data (no constraints & indices are recreated, including PK)::
+
+   CREATE TABLE mycopy AS (SELECT * FROM myorig);
+
+Create table from select (without copying data)::
+
+   CREATE TABLE mycopy AS (SELECT * FROM myorig) WITH NO DATA;
+
 JDBC driver
 ===========