Re: pg_get_serial_sequence not working for manually set seq

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marcelo Fernandes <marcefern7(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: pg_get_serial_sequence not working for manually set seq
Date: 2025-04-22 01:33:46
Message-ID: 878366.1745285626@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marcelo Fernandes <marcefern7(at)gmail(dot)com> writes:
> I've been testing the pg_get_serial_sequence function and noticed that I can
> only get reliable results when using a SERIAL or IDENTITY column.
> However, shouldn't it work for manually set sequences too?

pg_get_serial_sequence looks for pg_depend entries that make sequences
depend on columns, so no you won't get it to work that way.

You could use ALTER SEQUENCE OWNED BY to establish the dependency link,
if you are intent on reimplementing SERIAL by hand. See the
documentation about what SERIAL does:

https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message senor 2025-04-22 04:26:10 sequence on daily log partitioned table
Previous Message Marcelo Fernandes 2025-04-22 01:22:50 pg_get_serial_sequence not working for manually set seq