T
T
TempForWork2014-12-05 12:36:14
PostgreSQL
TempForWork, 2014-12-05 12:36:14

How to copy a table from one schema to another [PostgreSQL] ?

There is a base with two schemes - temp and public.
Public contains an empty TableOriginal table. There is no such table in the temp schema.
It is necessary to copy the TableOriginal table into the temp schema.
Schemas cannot be renamed because the set of tables and data in them differ.
In SQL Shell (psql) after entering the command:

CREATE TABLE temp.TableOriginal AS SELECT * FROM public.TableOriginal

no messages or errors appeared, but the table was not created.
Can you please tell me how to copy the table?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
krypt3r, 2014-12-05
@krypt3r

CREATE TABLE "temp"."TableOriginal" AS SELECT * FROM "public"."TableOriginal"

Not? Also look towards CREATE TABLE table_name (LIKE table_parent)

D
des1roer, 2015-04-01
@des1roer

It is possible to peep ddl, create a table. And then in a swoop throw all the data

INSERT INTO newshema.table  select * from oldshema.table;

O
Oleg M, 2017-03-29
@olpc

ALTER TABLE name
SET SCHEMA new_schema

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question