Re: system catalog relation of a table and a serial sequence - Mailing list pgsql-patches

From Tom Lane
Subject Re: system catalog relation of a table and a serial sequence
Date
Msg-id 14115.1008470612@sss.pgh.pa.us
Whole thread Raw
In response to Re: system catalog relation of a table and a serial sequence  (Brent Verner <brent@rcfile.org>)
Responses Re: system catalog relation of a table and a serial sequence  (Brent Verner <brent@rcfile.org>)
List pgsql-patches
Brent Verner <brent@rcfile.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

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: system catalog relation of a table and a serial sequence
Next
From: Brent Verner
Date:
Subject: Re: system catalog relation of a table and a serial sequence