Re: Insert/Dump/Restore table with generated columns - Mailing list pgsql-general

From David Rowley
Subject Re: Insert/Dump/Restore table with generated columns
Date
Msg-id CAApHDvp_gDVwnZvh9dQDfOmsj2QOX+v4uMK-4MWH2kjYTR6ogg@mail.gmail.com
Whole thread Raw
In response to Insert/Dump/Restore table with generated columns  (zickzack@quantentunnel.de)
Responses Re: Re: Insert/Dump/Restore table with generated columns
List pgsql-general
On Thu, 1 Jul 2021 at 22:06, <zickzack@quantentunnel.de> wrote:
> I have several tables with generated columns. If I restore the plain dumped data (insert statements from pg_dump)
I'llget the error message "Column xyz is a generated column.". The exception is understandably, no question (and is
welldocumented). In case of the error no insert takes place. 
> My problem now is that my simple backup/restore workflow is corrupted, cause those tables with generated column will
beempty. 

As far as I can see, this shouldn't happen.  I tried to recreate and I can't.

create table ab (a int, b int generated always as (a / 2) stored);
insert into ab values(1);

Running:

pg_dump --table=ab --column-inserts postgres

I see the following in the pg_dump output.

INSERT INTO public.ab (a, b) VALUES (1, DEFAULT);

pg_dump --table=ab --inserts postgres

gives:

INSERT INTO public.ab VALUES (1, DEFAULT);

both of these commands work fine when I run them on the existing database.

I tested this on current master, but looking at the history [1], it
looks like the pg_dump support was added when the feature went in, so
that indicates that it was not missed then subsequently fixed later.

Just to keep us from having to guess, are you able to share the
version of PostgreSQL you're running? Also, the version of pg_dump?
pg_dump --version will tell you that.

David

[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=fc22b6623b6b3bab3cb057ccd282c2bfad1a0b30



pgsql-general by date:

Previous
From: zickzack@quantentunnel.de
Date:
Subject: Insert/Dump/Restore table with generated columns
Next
From: Ron
Date:
Subject: Greatest of a list of columns?