BUG #14813: pg_get_serial_sequence does not return seqence name for IDENTITY columns

Started by zambak zambakabout 9 years ago7 messagesbugs
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t67856
psql -h localhost -U postgres

Built from patchset v6 (message #6), July 27, 2026 at 10:16 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t67856_6 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t67856_6 && git checkout t67856_6

Patchset v6 (message #6) is on t67856_6

Jump to latest
#1zambak zambak
zam6ak@gmail.com

The following bug has been logged on the website:

Bug reference: 14813
Logged by: zam zam
Email address: zam6ak@gmail.com
PostgreSQL version: 10beta4
Operating system: windows
Description:

Function pg_get_serial_sequence returns NULL on columns defined as
IDENTITY

CREATE TABLE IF NOT EXISTS public.test (
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
code text,

CONSTRAINT test_pk PRIMARY KEY (id)
)

SELECT pg_get_serial_sequence('public.test', 'id'); -- returns NULL instead
of 'test_id_seq'!

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: zambak zambak (#1)
Re: BUG #14813: pg_get_serial_sequence does not return seqence name for IDENTITY columns

On Tue, Sep 12, 2017 at 2:20 PM, <zam6ak@gmail.com> wrote:

The following bug has been logged on the website:

Bug reference: 14813
Logged by: zam zam
Email address: zam6ak@gmail.com
PostgreSQL version: 10beta4
Operating system: windows
Description:

Function pg_get_serial_sequence returns NULL on columns defined as
IDENTITY

CREATE TABLE IF NOT EXISTS public.test (
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
code text,

CONSTRAINT test_pk PRIMARY KEY (id)
)

SELECT pg_get_serial_sequence('public.test', 'id'); -- returns NULL
instead
of 'test_id_seq'!

​I suspect this is an opportunity for documentation enhancement as opposed
to a bug.

​The CREATE TABLE docs say that: "It will have an implicit sequence
attached to it." I take the word "implicit" to mean that an actual
external sequence object is not created.

David J.

#3zambak zambak
zam6ak@gmail.com
In reply to: David G. Johnston (#2)
Re: BUG #14813: pg_get_serial_sequence does not return seqence name for IDENTITY columns

On Tue, Sep 12, 2017 at 5:54 PM, David G. Johnston <
david.g.johnston@gmail.com> wrote:

On Tue, Sep 12, 2017 at 2:20 PM, <zam6ak@gmail.com> wrote:

The following bug has been logged on the website:

Bug reference: 14813
Logged by: zam zam
Email address: zam6ak@gmail.com
PostgreSQL version: 10beta4
Operating system: windows
Description:

Function pg_get_serial_sequence returns NULL on columns defined as
IDENTITY

CREATE TABLE IF NOT EXISTS public.test (
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
code text,

CONSTRAINT test_pk PRIMARY KEY (id)
)

SELECT pg_get_serial_sequence('public.test', 'id'); -- returns NULL
instead
of 'test_id_seq'!

​I suspect this is an opportunity for documentation enhancement as opposed
to a bug.

​The CREATE TABLE docs say that: "It will have an implicit sequence
attached to it." I take the word "implicit" to mean that an actual
external sequence object is not created.

David J.

But the sequence 'test_id_seq' is created....
To my understanding (and I may be wrong), identity columns are backed by
sequences in PG 10...

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: David G. Johnston (#2)
Re: BUG #14813: pg_get_serial_sequence does not return seqence name for IDENTITY columns

"David G. Johnston" <david.g.johnston@gmail.com> writes:

On Tue, Sep 12, 2017 at 2:20 PM, <zam6ak@gmail.com> wrote:

Function pg_get_serial_sequence returns NULL on columns defined as
IDENTITY

This seems like a reasonable complaint to me.

​I suspect this is an opportunity for documentation enhancement as opposed
to a bug.

The reason appears to be that the dependency setup for a sequence created
to support IDENTITY is randomly different from that for a serial sequence.
I'm not sure this is a good thing.

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#5Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#4)
Re: BUG #14813: pg_get_serial_sequence does not return seqence name for IDENTITY columns

Tom Lane wrote:

"David G. Johnston" <david.g.johnston@gmail.com> writes:

​I suspect this is an opportunity for documentation enhancement as opposed
to a bug.

The reason appears to be that the dependency setup for a sequence created
to support IDENTITY is randomly different from that for a serial sequence.
I'm not sure this is a good thing.

It would be bad to break queries all over the internet that assume that
sequences for columns can be found using pg_get_serial_sequence, so I
agree this should be fixed.

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#6Peter Eisentraut
peter_e@gmx.net
In reply to: Alvaro Herrera (#5)
Re: BUG #14813: pg_get_serial_sequence does not return seqence name for IDENTITY columns

On 9/13/17 09:25, Alvaro Herrera wrote:

Tom Lane wrote:

"David G. Johnston" <david.g.johnston@gmail.com> writes:

​I suspect this is an opportunity for documentation enhancement as opposed
to a bug.

The reason appears to be that the dependency setup for a sequence created
to support IDENTITY is randomly different from that for a serial sequence.
I'm not sure this is a good thing.

It would be bad to break queries all over the internet that assume that
sequences for columns can be found using pg_get_serial_sequence, so I
agree this should be fixed.

Proposed patch attached.

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

Attachments:

t67856_6
0001-Apply-pg_get_serial_sequence-to-identity-column-sequ.patchtext/plain; charset=UTF-8; name=0001-Apply-pg_get_serial_sequence-to-identity-column-sequ.patch; x-mac-creator=0; x-mac-type=0Download+43-21
#7Peter Eisentraut
peter_e@gmx.net
In reply to: Peter Eisentraut (#6)
Re: BUG #14813: pg_get_serial_sequence does not return seqence name for IDENTITY columns

On 9/14/17 17:15, Peter Eisentraut wrote:

On 9/13/17 09:25, Alvaro Herrera wrote:

Tom Lane wrote:

"David G. Johnston" <david.g.johnston@gmail.com> writes:

​I suspect this is an opportunity for documentation enhancement as opposed
to a bug.

The reason appears to be that the dependency setup for a sequence created
to support IDENTITY is randomly different from that for a serial sequence.
I'm not sure this is a good thing.

It would be bad to break queries all over the internet that assume that
sequences for columns can be found using pg_get_serial_sequence, so I
agree this should be fixed.

Proposed patch attached.

committed

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

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs