Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

How to create a sequence for a table which was created by selecting data from another table?

$
0
0

I have created a new table by selecting data from an existing table:

CREATE TABLE polygon2 AS
SELECT gid, geom
FROM polygon1;

CREATE SEQUENCE polygon2_gid_seq;
SELECT SETVAL('polygon2_gid_seq', (SELECT MAX(gid) FROM polygon2));

ALTER TABLE polygon2
ALTER COLUMN gid SET NOT NULL,
ALTER COLUMN gid SET DEFAULT nextval('polygon2_gid_seq'::regclass),
ADD CONSTRAINT polygon2_pkey PRIMARY KEY (gid);

Unfortunately neither QGIS nor pgAdmin are dropping the corresponding sequence when dropping the table. This issue doesn’t appear when dropping tables which were created using the QGIS ‘Create table’ dialog. So I suppose there is something missing in the way I’ve created the sequence. Can anybody please help me?


Viewing all articles
Browse latest Browse all 1138

Trending Articles