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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: system catalog relation of a table and a serial sequence
Дата
Msg-id 14115.1008470612@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: system catalog relation of a table and a serial sequence  (Brent Verner <brent@rcfile.org>)
Ответы Re: system catalog relation of a table and a serial sequence  (Brent Verner <brent@rcfile.org>)
Список 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 по дате отправления:

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