From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Jean Prulière <jean@oclock.io>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: Identity column behavior discrepancies when inserting one or many rows
Date: Mon, 12 Oct 2020 14:12:15 -0400
Message-ID: <3198997.1602526335@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYDz0tdYGAnT2r7nwBTsFjPyRd=+oObJ=MnuzSs-XQxdA@mail.gmail.com>
References: <CACYaYVVxiajieLxp74_c66fb2OXP=QZgTMxU6y9ERjWty3jL+w@mail.gmail.com>
<CAKFQuwYDz0tdYGAnT2r7nwBTsFjPyRd=+oObJ=MnuzSs-XQxdA@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Mon, Oct 12, 2020 at 4:04 AM Jean Prulière <jean@oclock.io> wrote:
>> Here is a very simple script to reproduce what we encountered :
>>
>> CREATE TABLE test (
>> id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
>> sometext text NOT NULL
>> );
>>
>> -- that one works : INSERT 0 1
>> -- I think it should not and throw a 428C9
>> INSERT INTO test (id, sometext)
>>
>> VALUES (DEFAULT, 'test');
>>
>> -- this one does not : SQL state : 428C9
>> INSERT INTO test (id, sometext)
>>
>> VALUES (DEFAULT, 'test2'),
>> (DEFAULT, 'test3');
> I agree the inconsistency seems to be undocumented but I wonder why the
> second case doesn't work, not why the first one does. INSERT says: "For a
> generated column, specifying this is permitted but merely specifies the
> normal behavior of computing the column from its generation expression."
> That says the first case works, default means the same as omitting the
> column altogether.
Yeah. Ideally both examples should work. The fact that the second one
does not is an implementation deficiency: the code that recognizes no-op
DEFAULTs for this purpose doesn't descend into multi-row VALUES lists.
Somebody submitted a patch to improve that awhile ago, but I didn't like
the first version and there hasn't been an update yet:
https://commitfest.postgresql.org/30/2681/
Perhaps you could get your students interested in rewriting that patch?
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, jean@oclock.io, pgsql-bugs@lists.postgresql.org
Subject: Re: Identity column behavior discrepancies when inserting one or many rows
In-Reply-To: <3198997.1602526335@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox