Re: derive the sequence name of a column

From: "Mel Jamero" <mel(at)gmanmi(dot)tv>
To: "'Bruno Wolff III'" <bruno(at)wolff(dot)to>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: derive the sequence name of a column
Date: 2003-10-30 07:05:44
Message-ID: 004c01c39eb4$3d73d890$1b06a8c0@cmpmel
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Thank for the reply Bruno but I need more. =)

Sorry, I have to send this again because I haven't figured out how to
solve this.

Can anyone please tell me exactly how the name of a sequence a field is
using (manually created or generated by a serial) could be derived
programmatically (using libpq or through SQL)?

Thus:

CREATE SEQUENCE an_unknown_sequence_name;
CREATE TABLE test (
test_id integer default nextval('an_unknown_sequence_name'),
useless_redundant_test_id serial
);

How do I programmatically extract that column 'test_id' in table 'test'
is using 'an_unknown_sequence_name'

TIA!

Mel

-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Bruno Wolff III
Sent: Monday, October 27, 2003 11:45 AM
To: Mel Jamero
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] derive the sequence name of a column

On Fri, Oct 24, 2003 at 15:41:00 +0800,
Mel Jamero <mel(at)gmanmi(dot)tv> wrote:
> Hi!

Please don't reply to messages to start new threads.

>
> Can anyone please tell me exactly how the name of a sequence a field
is
> using (manually created or generated by a serial) could be derived
> programmatically (using libpq or through SQL)?

When creating a sequence for a serial type, for short names the format
is
tablename underline columnname underline seq . If the resulting name is
longer
than 63 characters then something else is used so as to get a shorter
name.
If you have control over the table and column names than you can make
sure the
names are always short enough so that the simple algorithm is used.

For manually created references to sequences, you will probably need to
parse the default value. I don't know how to do this, but using the
-E on pgsql and using \d sampletable should show you what query to use.

>
> Thus:
>
> CREATE SEQUENCE an_unknown_sequence_name;
> CREATE TABLE test (
> test_id integer default nextval('an_unknown_sequence_name'),
> useless_redundant_test_id serial
> );
>
> How do I programmatically extract that column 'test_id' in table
'test'
> is using 'an_unknown_sequence_name'

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Pedro Miguel Guedes 2003-10-30 08:38:42 help from Portugal
Previous Message Tom Lane 2003-10-29 22:35:05 Re: Capturing vacuum output