Re: system catalog relation of a table and a serial sequence

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Brent Verner <brent(at)rcfile(dot)org>
Cc: pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: system catalog relation of a table and a serial sequence
Date: 2001-12-16 02:43:32
Message-ID: 14115.1008470612@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Brent Verner <brent(at)rcfile(dot)org> writes:
> 1) Is a strcmp(firststrtok,"nextval('") == 0 sufficient to determine
> that the adsrc is indeed one that we're looking for? If not,
> suggestions are greatly appreciated :-)

I would not use strtok at all, but look for nextval('" at the start
of the string and "'::text) at the end. If both match, and there's
at least one character between, then the intervening text can be
presumed to be a sequence name. You might further check that the
apparent sequence name ends with _seq --- if not, it wasn't generated
by SERIAL.

> 2) Should this function now look like .. ?
> char** getSerialSequenceNames(const char* table)
> Or would you suggest it return a smarter struct?

char** (null-terminated vector) would probably work.

BTW, don't forget you have the OID of the table available from the table
list, so you can avoid the subselect, as well as the relname quoting
issues that you didn't take care of. When a tablename argument is
provided, I'd be inclined to make a pre-pass over the table list to see
if it matches any non-sequence table names, and if so build a list of
their associated sequence name(s). Keep in mind that we'll probably
generalize the tablename argument to support wildcarding someday soon,
so it'd be good if the code could cope with more than one matching
table.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brent Verner 2001-12-16 04:00:06 Re: system catalog relation of a table and a serial sequence
Previous Message Brent Verner 2001-12-16 02:29:07 Re: system catalog relation of a table and a serial sequence

Browse pgsql-patches by date

  From Date Subject
Next Message Brent Verner 2001-12-16 04:00:06 Re: system catalog relation of a table and a serial sequence
Previous Message Brent Verner 2001-12-16 02:29:07 Re: system catalog relation of a table and a serial sequence