Thread: RETURNING id problem with insert.

RETURNING id problem with insert.

From
-
Date:
RETURNING id problem with insert.

Hello everyone.
Iam trying to do an insert for return generated id INSERT RETURNING id. In postgres editor it work without problems, but in code execution - java 1.6 with iBatis 3 (8.4 postgres driver version 8.4-702) gives the error - Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near " RETURNING. "
It this means Postgres does not support Returning to insert?


but not how to do <statement ... Second answer, I get error iBatis xml editor. I think it's for iBatis 2 version.

Thank you very much for responding.


Español.
Problema con RETURNING id con insert.

Hola a todos.

Intento hacer un insert y que me devuelva id generada con  INSERT .... RETURNING id. En editor de postgres funcciona sin problemas, pero en ejecucion java 1.6 con iBatis 3 (version postgres 8.4 driver 8.4-702)  da el error - Caused by: org.postgresql.util.PSQLException: ERROR: error de sintaxis en o cerca de «RETURNING». 
Postgres no soporta returning con insert ?


pero no se como hacer <statement ... de segunda respuesta,  me da error editor xml de iBatis. Pienso que es para version iBatis 2

Muchas gracias por responder.




Re: RETURNING id problem with insert.

From
Dave Cramer
Date:
Have a look at the postgresql logs to see what ibatis is actually
generating. There is no reason it should not work

Dave

On Tue, Dec 7, 2010 at 1:49 PM, - <grandebuzon@gmail.com> wrote:
> RETURNING id problem with insert.
> Hello everyone.
> Iam trying to do an insert for return generated id INSERT RETURNING id. In
> postgres editor it work without problems, but in code execution - java 1.6
> with iBatis 3 (8.4 postgres driver version 8.4-702) gives the error - Caused
> by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "
> RETURNING. "
> It this means Postgres does not support Returning to insert?
> I found this online -
> http://stackoverflow.com/questions/1769595/concurrency-issues-when-retriveing-ids-of-newly-inserted-rows-with-ibatis
> but not how to do <statement ... Second answer, I get error iBatis xml
> editor. I think it's for iBatis 2 version.
> Thank you very much for responding.
>
> Español.
> Problema con RETURNING id con insert.
> Hola a todos.
> Intento hacer un insert y que me devuelva id generada con  INSERT ....
> RETURNING id. En editor de postgres funcciona sin problemas, pero en
> ejecucion java 1.6 con iBatis 3 (version postgres 8.4 driver 8.4-702)  da el
> error - Caused by: org.postgresql.util.PSQLException: ERROR: error de
> sintaxis en o cerca de «RETURNING».
> Postgres no soporta returning con insert ?
> He encontrado esto en internet -
> http://stackoverflow.com/questions/1769595/concurrency-issues-when-retriveing-ids-of-newly-inserted-rows-with-ibatis
> pero no se como hacer <statement ... de segunda respuesta,  me da error
> editor xml de iBatis. Pienso que es para version iBatis 2
> Muchas gracias por responder.
>
>
>
>

Re: RETURNING id problem with insert.

From
-
Date:
With this code, always returns 1 instead of new generated ID

 <insert id="insertNewItem" parameterType="itemAlias" useGeneratedKeys="true" keyProperty="item_id">
INSERT INTO items (
category_id,
description,
...)
VALUES(
#{category_id},
#{description},
...)    
  </insert>

and if I put RETURNING item_id at the end of insert,

......
VALUES(
#{category_id},
#{description},
...) RETURNING item_id
   
  </insert>


 fails with error in the postgres log - syntax error at or near "RETURNING"

........$12,
$13,
$14)
RETURNING item_id RETURNING *



2010/12/7 Dave Cramer <pg@fastcrypt.com>
Have a look at the postgresql logs to see what ibatis is actually
generating. There is no reason it should not work

Dave

On Tue, Dec 7, 2010 at 1:49 PM, - <grandebuzon@gmail.com> wrote:
> RETURNING id problem with insert.
> Hello everyone.
> Iam trying to do an insert for return generated id INSERT RETURNING id. In
> postgres editor it work without problems, but in code execution - java 1.6
> with iBatis 3 (8.4 postgres driver version 8.4-702) gives the error - Caused
> by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "
> RETURNING. "
> It this means Postgres does not support Returning to insert?
> I found this online -
> http://stackoverflow.com/questions/1769595/concurrency-issues-when-retriveing-ids-of-newly-inserted-rows-with-ibatis
> but not how to do <statement ... Second answer, I get error iBatis xml
> editor. I think it's for iBatis 2 version.
> Thank you very much for responding.
>
> Español.
> Problema con RETURNING id con insert.
> Hola a todos.
> Intento hacer un insert y que me devuelva id generada con  INSERT ....
> RETURNING id. En editor de postgres funcciona sin problemas, pero en
> ejecucion java 1.6 con iBatis 3 (version postgres 8.4 driver 8.4-702)  da el
> error - Caused by: org.postgresql.util.PSQLException: ERROR: error de
> sintaxis en o cerca de «RETURNING».
> Postgres no soporta returning con insert ?
> He encontrado esto en internet -
> http://stackoverflow.com/questions/1769595/concurrency-issues-when-retriveing-ids-of-newly-inserted-rows-with-ibatis
> pero no se como hacer <statement ... de segunda respuesta,  me da error
> editor xml de iBatis. Pienso que es para version iBatis 2
> Muchas gracias por responder.
>
>
>
>

Re: RETURNING id problem with insert.

From
Dave Cramer
Date:
On Tue, Dec 7, 2010 at 5:05 PM, - <grandebuzon@gmail.com> wrote:
> With this code, always returns 1 instead of new generated ID
>  <insert id="insertNewItem" parameterType="itemAlias"
> useGeneratedKeys="true" keyProperty="item_id">
> INSERT INTO items (
> category_id,
> description,
> ...)
> VALUES(
> #{category_id},
> #{description},
> ...)
>   </insert>
> and if I put RETURNING item_id at the end of insert,
> ......
> VALUES(
> #{category_id},
> #{description},
> ...) RETURNING item_id
>
>   </insert>
>
>  fails with error in the postgres log - syntax error at or near "RETURNING"
> ........$12,
> $13,
> $14)
> RETURNING item_id RETURNING *

It appears that Ibatis added RETURNING * after your RETURNING item_id.
I'd speak to them to see how to do it properly.

Dave

Re: RETURNING id problem with insert.

From
-
Date:

no way to return new id with iBatis3 always return - 1  :(



2010/12/7 Dave Cramer <pg@fastcrypt.com>
On Tue, Dec 7, 2010 at 5:05 PM, - <grandebuzon@gmail.com> wrote:
> With this code, always returns 1 instead of new generated ID
>  <insert id="insertNewItem" parameterType="itemAlias"
> useGeneratedKeys="true" keyProperty="item_id">
> INSERT INTO items (
> category_id,
> description,
> ...)
> VALUES(
> #{category_id},
> #{description},
> ...)
>   </insert>
> and if I put RETURNING item_id at the end of insert,
> ......
> VALUES(
> #{category_id},
> #{description},
> ...) RETURNING item_id
>
>   </insert>
>
>  fails with error in the postgres log - syntax error at or near "RETURNING"
> ........$12,
> $13,
> $14)
> RETURNING item_id RETURNING *

It appears that Ibatis added RETURNING * after your RETURNING item_id.
I'd speak to them to see how to do it properly.

Dave