From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Identity columns, DEFAULT keyword and multi-row inserts
Date: Tue, 10 Dec 2019 09:15:11 +0100
Message-ID: <6615c093-b124-d680-e489-539ed98cf18b@gmx.net> (raw)
In-Reply-To: <DB6PR0501MB2359C8C9E765DFF4DAA48CBCEF5B0@DB6PR0501MB2359.eurprd05.prod.outlook.com>
References: <ae6d3563-f3c9-ce42-1f2c-32934e844505@gmx.net>
<DB6PR0501MB2359C8C9E765DFF4DAA48CBCEF5B0@DB6PR0501MB2359.eurprd05.prod.outlook.com>
Patrick FICHE schrieb am 10.12.2019 um 08:56:
>> -----Original Message-----
>> From: Thomas Kellerer <spam_eater@gmx.net>
>>
>> assume the following table:
>>
>> create table test
>> (
>> id integer not null generated always as identity,
>> data integer not null
>> );
>>
>> However, a multi-row insert like the following:
>>
>> insert into test (id, data)
>> values
>> (default,1),
>> (default,2);
>>
>> fails with:
>>
>> ERROR: cannot insert into column "id"
>> Detail: Column "id" is an identity column defined as GENERATED ALWAYS.
>> Hint: Use OVERRIDING SYSTEM VALUE to override.
>>
>>
>> My question is:
>>
>> * If DEFAULT is not allowed for identity columns, then why does the single-row insert work?
>> * If DEFAULT _is_ allowed, then why does the multi-row insert fail?
>
>
> I agree that it does not seem very consistent.
>
> But is there any specific reason why are you using DEFAULT ?
>
> If you want / have to specify DEFAULT, then you should probably
> create your identity as "generated by default".
I don't really need (or use) it, I just stumbled upon this: https://stackoverflow.com/questions/59261048
And I think if the single row insert is allowed the multi-row should be as well.
Not sure if this is a bug - and if it is, which one is the bug: the failing statement or the working one?
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: spam_eater@gmx.net
Subject: Re: Identity columns, DEFAULT keyword and multi-row inserts
In-Reply-To: <6615c093-b124-d680-e489-539ed98cf18b@gmx.net>
References: <ae6d3563-f3c9-ce42-1f2c-32934e844505@gmx.net> <DB6PR0501MB2359C8C9E765DFF4DAA48CBCEF5B0@DB6PR0501MB2359.eurprd05.prod.outlook.com> <6615c093-b124-d680-e489-539ed98cf18b@gmx.net>
* 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