Rough idea for supporting "sequencename.nextval" syntax

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Rough idea for supporting "sequencename.nextval" syntax
Дата
Msg-id 7539.997922214@sss.pgh.pa.us
обсуждение исходный текст
Ответы Re: Rough idea for supporting "sequencename.nextval" syntax  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
I have what may be a half-baked idea for allowing nextval and friends to
work with a true sequence-name parameter, rather than a string
equivalent.

Suppose that we invent a new datatype "regclass", similar to regproc:
it's actually an OID, but it has the additional implication that it is
the OID of a pg_class row, and the I/O operations for the type try to
accept or print a class name not just a numeric OID.

Next, hack the parser to understand that when a function has an argument
declared as type regclass and is invoked with the syntax relname.func or
func(relname), what is wanted is for the OID of the relation to be
passed as a constant argument; the relation is NOT inserted into the
query's rangetable.

Then, it's a simple matter to write a variant of nextval that identifies
its target sequence by OID rather than name.  The function will still be
responsible for ensuring that what it's pointed at is indeed a sequence,
since the parser won't enforce that.

I haven't yet studied the parser to see how much of a hack this would
be, but it seems doable.  The facility might be of use for other
functions besides the sequence ones, too.

Thoughts?
        regards, tom lane


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

Предыдущее
От: Hiroshi Inoue
Дата:
Сообщение: Re: PL/pgSQL bug?
Следующее
От: Tatsuo Ishii
Дата:
Сообщение: Re: encoding names