Re: BUG #14952: COPY fails to fill in IDENTITY column default value

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: steven(dot)winfield(at)cantabcapital(dot)com, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14952: COPY fails to fill in IDENTITY column default value
Date: 2017-12-15 17:37:20
Message-ID: 21a6da72-fb24-4b9e-d300-7439425f7492@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 12/13/17 22:39, Tom Lane wrote:
> Now that I look more closely at this patch, isn't it fixing things
> in the wrong place? Why is it that COPY needs to know about this,
> rather than build_column_default()? Aren't we going to have to
> fix every other caller of build_column_default()?

Yeah, that seems to be a problem. Attached is a patch that puts the
logic into build_column_default() and adds a few more tests covering
other omissions.

One problem is that this breaks the case ALTER TABLE ... ADD COLUMN ...
IDENTITY, because the sequence ownership isn't registered until after
the ALTER TABLE command. (This only worked for empty tables. For
pre-populated tables, it failed because of the above omission.) The
second patch tries to fix that. Needs more thought and documentation,
but it's an idea.

> For that matter, should build_column_default() know about it explicitly
> either? Why aren't we implementing IDENTITY by storing an appropriate
> default expression in the catalogs?

Initial versions were coded that way, but it was pretty messy and buggy
because you have to touch a lot of places to teach them the difference
between a real default expression and a synthetic one. Another problem
is that the NextValueExpr has special permission behavior that is not
really representable by a normal expression, thus introducing more
special cases, and possibly permission or security issues.

Obviously, it would have helped in the above case. But it was really messy.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
0001-Apply-identity-column-expression-in-build_column_def.patch text/plain 7.2 KB
0002-Fix-ALTER-TABLE-ADD-COLUMN-IDENTITY.patch text/plain 5.4 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message eike 2017-12-15 21:26:56 pg_restore --create --no-tablespaces should not issue 'CREATE DATABASE ... TABLESPACE'
Previous Message Esteban Zimanyi 2017-12-15 17:20:23 Memory leak with SP-GIST indexes