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

From: Brent Verner <brent(at)rcfile(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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 04:00:06
Message-ID: 20011216040006.GA7161@rcfile.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

[2001-12-15 21:43] Tom Lane said:
| 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.

Why not use strtok? The following should be safe, no?

t1 = strtok(adsrc,"\"");
t2 = strtok(NULL,"\"");
t3 = strtok(NULL,"\"");

if( t0 && t2
&& strcmp(t0,"nextval('") == 0
&& strcmp(t2,"'::text)") == 0 ){
/* this is a call to nextval, check for t1 =~ /_seq$/ */

}

| > 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.

gotcha.

thanks.
brent

--
"Develop your talent, man, and leave the world something. Records are
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing." -- Duane Allman

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brent Verner 2001-12-16 04:03:32 Re: [HACKERS] system catalog relation of a table and a serial sequence
Previous Message Tom Lane 2001-12-16 02:43:32 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:03:32 Re: [HACKERS] system catalog relation of a table and a serial sequence
Previous Message Tom Lane 2001-12-16 02:43:32 Re: system catalog relation of a table and a serial sequence