Answer the question
In order to leave comments, you need to log in
How to create a table from another using a different sequence for the id column?
Reading the Postgres documentation.
https://postgrespro.ru/docs/postgresql/10/sql-crea...
It says the following
The identity characteristic in the definition of the copied column will only be copied if the command has an INCLUDING IDENTITY clause. For each identity column in the new table, a new sequence is created, independent of the sequences associated with the old table.
create table b_table (like newtable INCLUDING COMMENTS INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING INDEXES);
Answer the question
In order to leave comments, you need to log in
melkij=> create table identity_test (i int primary key generated by default as identity, val int);
CREATE TABLE
melkij=> insert into identity_test (val) values (1);
INSERT 0 1
melkij=> table identity_test;
i | val
---+-----
1 | 1
(1 строка)
melkij=> create table identity_test_like (like identity_test INCLUDING COMMENTS INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING INDEXES);
CREATE TABLE
melkij=> \d identity_test_like
Таблица "public.identity_test_like"
Столбец | Тип | Правило сортировки | Допустимость NULL | По умолчанию
---------+---------+--------------------+-------------------+--------------
i | integer | | not null |
val | integer | | |
Индексы:
"identity_test_like_pkey" PRIMARY KEY, btree (i)
melkij=> \d identity_test
Таблица "public.identity_test"
Столбец | Тип | Правило сортировки | Допустимость NULL | По умолчанию
---------+---------+--------------------+-------------------+----------------------------------
i | integer | | not null | generated by default as identity
val | integer | | |
Индексы:
"identity_test_pkey" PRIMARY KEY, btree (i)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question