Re: BUG #14756: Inserting row with PK IDENTITY column fails 1st time

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: zam6ak(at)gmail(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14756: Inserting row with PK IDENTITY column fails 1st time
Date: 2017-08-02 18:22:55
Message-ID: 0ddc33be-4961-673e-331f-9e98a37f3f79@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 7/23/17 21:25, zam6ak(at)gmail(dot)com wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14756
> Logged by: zam zam
> Email address: zam6ak(at)gmail(dot)com
> PostgreSQL version: 10beta2
> Operating system: docker for windows 17.06 ce
> Description:
>
> - table with PK IDENTITY COLUMN
> - insert 1st row and specify PK value (OVERRIDING)
> - insert 2nd row using defaults (fails)
> - try same command again (succeeds)
>
> The failure is only on the 1st attempt.

This is working correctly, AFAICT. When you insert an explicit value
into the identity column, the sequence is not advanced.

> -- but now, neither of these works ("ERROR: duplicate key value violates
> unique constraint "audit_pk"")
> -- THEY ONLY DON"T WORK 1st TIME you try (either statement),
> -- on 2nd attept each succeeds (My guess 1st time sequence is
> updated/corrected so 2nd time it goes through)

That is correctly observed.

> INSERT INTO public.audit VALUES (DEFAULT, 'public.audit'::regclass,
> 'public', 'audit');
> INSERT INTO public.audit (relation_id, schema_name, table_name) VALUES
> ('public.audit'::regclass, 'public', 'audit');
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Geoghegan 2017-08-02 18:28:49 Re: Crash report for some ICU-52 (debian8) COLLATE and work_mem values
Previous Message Peter Eisentraut 2017-08-02 16:41:50 Re: Re: [BUGS] BUG #14758: Segfault with logical replication on a function index