I'm trying to "copy/paste" rows of a table with bigserial
id
column, without listing all columns names in the query. There is a related post https://stackoverflow.com/a/15344327, which does not work with psql.
The isses is that psql does not trigger auto increment, when inserting NULL values.
The minimal case is
CREATE TABLE src (
id bigserial,
txt text NOT NULL);
INSERT INTO src (
txt)
VALUES (
'a'),
(
'b'),
(
'c'),
(
'b'
);
CREATE temp TABLE src_temp AS
SELECT
*
FROM
src
WHERE
txt = 'b';
UPDATE
src_temp
SET
id = NULL;
INSERT INTO src
SELECT
*
FROM
src_temp;
resulting in:
ERROR: null value in column "id" of relation "src" violates not-null constraint Detail: Failing row contains (null, b).
The practical case is that there are way more columns in the src
table.
Is there any way to make it?