Re: On Insert Do Instead Select....

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: On Insert Do Instead Select....
Дата
Msg-id jdk5ur$kho$2@dough.gmane.org
обсуждение исходный текст
Ответ на On Insert Do Instead Select....  (Daniel Jeffery <daniel.viviotech@gmail.com>)
Список pgsql-jdbc
Daniel Jeffery wrote on 30.12.2011 01:30:
> Is it at all possible for an executed insert statement to return a
> select statement resultset?
>
> Here's an example table:
>
> /CREATE TABLE test (/ /  id integer NOT NULL DEFAULT nextval(
> 'test_id_seq'::regclass ),/ /  column_name text/ /);/ / / / / Here's
> the table's rule:
>
> /CREATE RULE replace_test AS ON INSERT TO test WHERE EXISTS( SELECT 1
> FROM test WHERE (column_name = NEW.column_name) ) DO INSTEAD SELECT
> test.id <http://test.id> FROM test WHERE column_name =
> NEW.column_name;/ / / / / How would I get the JDBC driver to return
> the resultset?

I haven't tried it, but using Statement.execute() (instead of executeUpdate()) should do it.

Then you need to call getMoreResults(), getResults(), getUpdateCount() to get everything.

Pay attention to the javadocs of Statement.getUpdateCount() and Statement.getMoreResults() describing the condition how
todetect if there are no more results/update counts to retrieve. 

It's essentially the same as retrieving the data returned by an INSERT ... RETURNING.



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

Предыдущее
От: Daniel Jeffery
Дата:
Сообщение: On Insert Do Instead Select....
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: JDBC builds broken