Re: Patch for Statement.getGeneratedKeys()

From: Ken Johanson <pg-user(at)kensystem(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Patch for Statement.getGeneratedKeys()
Date: 2008-01-16 07:09:29
Message-ID: 478DADA9.2060700@kensystem.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

Tom Lane wrote:
> Kris Jurka <books(at)ejurka(dot)com> writes:
>> You need to look through the schemas in the search_path in order and see
>> which one a table with the given name appears in first.
>
> I've lost track of the context in which this needs to be done, but in
> some cases a cast to or from regclass offers a painless way to
> disambiguate table names. Just a suggestion ...
>

Tom, can you offer an example of this and how the overall goal might be
achieved? Kris, please jump in where I'm missing anything:

#Overview:
We need to implement:
Statement.executeUpdate(String sql, int columnIndexes[])

Current strategy is to find the natural column order (ordinal positions
for columnIndexes[]) and extract those names, passing them through to:
Statement.executeUpdate(String sql, String columnIndexes[])

To get the column names, I need to look in [the pg_* table equiv to
information_schema] tables, and of course this means knowing which table
is being referenced for modification. We are already parsing the table
name (fully or partially qualified) from the DML; now we need to search
[information_schema], finding the matching catalog, schema, and table,
and searching schema in the order of the schema search-path.

#History
Most interesting probably is that Kris mentioned it would work to just
do a INSERT.. RETURNING * to get the keys, however I'm electing to try
the extra-mile / "hard way" to save returning LOBs or entire multi-row
inserts. Ideally I's like to do everything in one extra query to
[information_schema] or better yet in RETURNING.

#Now
I'm a bit perplexed as to how I could get the current-ref'd schema using
one query. I think it might involve passing a subselect of "SHOW
search_path" as the arg to the [information_schema] query, but using
that var as a list and filling the $user var is not familiar ground...

#Questions:

-would the regclass-cast technique (I have no experience with it) work
directly in the RETURNING or need to be in the [information_schema]
query? Can you point me to examples?

-would it be feasible to modify RETURNING in new server versions to
accept indexes as args? That would obviate this whole discussion.

Thanks,
Ken

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kris Jurka 2008-01-16 07:20:28 Re: Patch for Statement.getGeneratedKeys()
Previous Message Joshua D. Drake 2008-01-16 05:57:06 Re: ATTN: Clodaldo was Performance problem. Could it be related to 8.3-beta4?

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2008-01-16 07:20:28 Re: Patch for Statement.getGeneratedKeys()
Previous Message Josh Berkus 2008-01-16 02:45:46 Re: [sfpug] PostgreSQL + Java devlopers wanted for JavaOne