From: Ken Johanson <pg-user@kensystem.com>
To: pgsql-general@postgresql.org
Subject: Re: RETURNING clause: how to specifiy column indexes?
Date: Wed, 12 Dec 2007 23:37:50 -0700
Message-ID: <4760D33E.40004@kensystem.com> (raw)
In-Reply-To: <Pine.BSO.4.64.0712120138360.1768@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>
Kris Jurka wrote:
>
> I think the expectation is that:
>
> CREATE TABLE t(a int, b int);
> INSERT INTO t(b,a) VALUES (1,2) RETURNING *;
>
> will return 1,2 instead of 2,1 as it does now. In this case the op is
> not expecting that the (potentially reorganized) table order is driving
> the results, but the order that they've actually specified the columns
> in creates the result.
>
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...
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?
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.
Is there a more elegant approach, like?:
INSERT... RETURNING (PG_LIST_KEYS(tblname))
I looked but did not find such a utility. It seems that such function
would be best implemented in the server instead of in a driver (eg.
having hardcoded subquery to the schema).
Ken
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: pg-user@kensystem.com, pgsql-general@postgresql.org
Subject: Re: RETURNING clause: how to specifiy column indexes?
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>
* 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