Re: DELETE ... RETURNING

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: DELETE ... RETURNING
Дата
Msg-id D960CB61B694CF459DCFB4B0128514C203937E2A@exadv11.host.magwien.gv.at
обсуждение исходный текст
Ответ на DELETE ... RETURNING  (Thomas Kellerer <spam_eater@gmx.net>)
Список pgsql-jdbc
Thomas Kellerer wrote:
> when using the RETURNING clause in a DELETE statement the
> driver throws an error:
>
> org.postgresql.util.PSQLException: A result was returned when
> none was expected.
>
> The code that I'm using is as follows:
>
> Statement stmt = connection.createStatement();
> stmt.executeUpdate("delete from person where firstname like 'A%' returning id");
>
> Am I missing something or is the "RETURNING" feature not
> supported by the driver?
>
> I'm using postgresql-8.4-701.jdbc3.jar with Java5

That's easy; when you issue an SQL statement that returns a result,
you cannot use executeUpdate(java.lang.String).

Use executeQuery(java.lang.String) or execute(java.lang.String) and then getResultSet().

It does not matter whether the statement starts with SELECT or DELETE, the important
point is whether it returns a result set or not.

See for reference:
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html

Yours,
Laurenz Albe

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

Предыдущее
От: Ken Johanson
Дата:
Сообщение: An eta for ResultSetMetaData getTableName, getSchemaName, getCatalogName?
Следующее
От: "devAng@libero.it"
Дата:
Сообщение: SSL & client config.