Re: Sequence names have 64 character limit?

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Carlo Stonebanks <carlo(at)stonebanks(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Sequence names have 64 character limit?
Date: 2011-03-31 22:15:01
Message-ID: 4D94FCE5.7000700@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 03/31/2011 02:47 PM, Carlo Stonebanks wrote:
> Thanks Adrian and Jerry.
>
> Technically, the best way to know which sequence a column is dependent on is
> to actually query for it. I have functions which query
> information_schema.columns and run a regex_replace to extract the sequence
> name from the defaulting nextval() expression. This is better than demanding
> that sequence names are predictable, but I wonder if there isn't a better
> query to run that doesn't require parsing texts? Obviously PG knows about
> the sequence's relation, probably via a dependency that finds it by
> rendering the text to regclass to an OID... but this stuff makes me nervous.
>
> So, a query that returns the sequence name (as text, you can cast to
> regclass!) associated with a particular column, that would return NUL if
> there was none... I don't suppose anyone has written such a query before...?
>
> Yes, I'd write a function around it!
>
> Thanks again,
>
> Carlo

Well in 8.2+ for sequences created by the SERIAL datatype there is the
function:
pg_get_serial_sequence(table_name, column_name)

The benefit of using SERIAL is that it sets up a dependency.
If you specify the sequence via CREATE SEQUENCE then AFAIK you are left
looking up the default and parsing it.

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Carlo Stonebanks 2011-03-31 23:04:37 Re: Sequence names have 64 character limit?
Previous Message Jerry Sievers 2011-03-31 22:14:44 Re: Sequence names have 64 character limit?