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

Поиск
Список
Период
Сортировка
От Brent Verner
Тема Re: system catalog relation of a table and a serial sequence
Дата
Msg-id 20011216040006.GA7161@rcfile.org
обсуждение исходный текст
Ответ на Re: [PATCHES] system catalog relation of a table and a serial sequence  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: system catalog relation of a table and a serial sequence  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
[2001-12-15 21:43] Tom Lane said:
| 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.

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

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [PATCHES] system catalog relation of a table and a serial sequence
Следующее
От: Brent Verner
Дата:
Сообщение: Re: [PATCHES] system catalog relation of a table and a serial sequence