From: Kris Jurka <books@ejurka.com>
To: Ken Johanson <pg-user@kensystem.com>
Cc: pgsql-general@postgresql.org
Subject: Re: RETURNING clause: how to specifiy column indexes?
Date: Thu, 13 Dec 2007 01:57:06 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0712130149270.6192@leary.csoft.net> (raw)
In-Reply-To: <4760D33E.40004@kensystem.com>
References: <22a9f7570703301215y44a937d0r5faa706bad7948c@mail.gmail.com>
<4610AA0C.30608@ejurka.com>
<47579D44.6060005@kensystem.com>
<47579FBE.1070503@kensystem.com>
<475F7766.2040005@kensystem.com>
<12796.1197439644@sss.pgh.pa.us>
<Pine.BSO.4.64.0712120138360.1768@leary.csoft.net>
<4760D33E.40004@kensystem.com>
On Wed, 12 Dec 2007, Ken Johanson wrote:
> Kris, do you have pointers to a spec that says the named-columns should
> specify the index, or that it should instead be the order in the table? My
> interpretation from the JDBC spec was that the latter is true, I may be
> wrong...
No, I was actually misremembering what the JDBC spec said, although I
think it's an interesting case to consider regardless of any specs.
> In the case where it is table-order, then I presume in PG that the "natural"
> order of the columns (even if reordering is allowed at a alter date) is
> specified by data in one of the pg_* tables (pg_class, pg_index, etc). Does
> anyone know if this is true/false?
pg_attribute.attnum stores column order at the moment. If/when
reordering is allowed, there will be another column indicating the
logical order of the colums.
> If true, my next idea would be to derive the column name using a subquery in
> the returning clause. But it sounds like this may have potential security
> contraints (will any INSERT query always have read access to the PG tables?).
> And no guarantee of the order matching in the long term.
There is no requirement that insert permission on a user table implies
read access to pg_catalog. Still many clients will break if they can't
read pg_catalog. For example, all of the JDBC driver's MetaData results
need to query pg tables, updatable ResultSets need to query pg tables to
know what the primary key is and so on. So if this functionality required
access to pg_catalog that would neither be unprecedented nor unreasonable.
> Is there a more elegant approach, like?:
>
> INSERT... RETURNING (PG_LIST_KEYS(tblname))
>
You can't dynamically derive the returning clause for the same reason you
can't say "INSERT INTO (SELECT myfunc()) VALUES (...)", using myfunc to
determine the table name at runtime. The planner needs to know all the
tables/columns/other database parts up front before executing anything.
Kris Jurka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, pg-user@kensystem.com, pgsql-general@postgresql.org
Subject: Re: RETURNING clause: how to specifiy column indexes?
In-Reply-To: <Pine.BSO.4.64.0712130149270.6192@leary.csoft.net>
References: <22a9f7570703301215y44a937d0r5faa706bad7948c@mail.gmail.com> <4610AA0C.30608@ejurka.com> <47579D44.6060005@kensystem.com> <47579FBE.1070503@kensystem.com> <475F7766.2040005@kensystem.com> <12796.1197439644@sss.pgh.pa.us> <Pine.BSO.4.64.0712120138360.1768@leary.csoft.net> <4760D33E.40004@kensystem.com> <Pine.BSO.4.64.0712130149270.6192@leary.csoft.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox