Rough idea for supporting "sequencename.nextval" syntax - Mailing list pgsql-hackers

From Tom Lane
Subject Rough idea for supporting "sequencename.nextval" syntax
Date
Msg-id 7539.997922214@sss.pgh.pa.us
Whole thread Raw
Responses Re: Rough idea for supporting "sequencename.nextval" syntax
List 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 by date:

Previous
From: Hiroshi Inoue
Date:
Subject: Re: PL/pgSQL bug?
Next
From: Tatsuo Ishii
Date:
Subject: Re: encoding names