Re: [GENERAL] rollback in C functions

2015-02-20 Thread Juan Pablo L
Just an update, it was making a mistake, the execution of PQexecute, to execute the query, was wrapped in a function called PGresult *db_execute() that was returning the PGresult as NULL, i completely forgot this, inside that function the exception was being caught and discarded so by the time

[GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Hello, i have created a function (in C) that receives an array that contains tuples of ID's and values. The function is to execute updates on each ID assigning the value, but if one of these operation fails (does not meet certain criteria) inside the function i would like to rollback and leave

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Chris Mair
The function is to execute updates on each ID assigning the value, but if one of these operation fails (does not meet certain criteria) inside the function i would like to rollback and leave everything untouched, in case other ID;s were already updated previously, and come back to the caller

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Hi Thanks Chris, yes i have already tested ereport and even made up my own sql state to report and error but from the application i can not access this error code directly (through the PQexec,PQresultErrorField,etc functions because the PGresult returns NULL) but i have to register a callback

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Alvaro Herrera
Juan Pablo L wrote: Hello, i have created a function (in C) that receives an array that contains tuples of ID's and values. Why are you writing a C function? Sounds like you could accomplish the same with a plpgsql function, with much less effort. The function is to execute updates on each

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Thank you Alvaro, i m afraid ereport seems to be the way, that it is complicated to catch this error code in the code of the caller. cause you have to use a callback etc etc On 19 February 2015 at 15:57, Alvaro Herrera alvhe...@2ndquadrant.com wrote: Juan Pablo L wrote: Hi, i want previous

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Hi, i want previous updates to rollback ... like nothing happened (a normal begin/rollback behaviour) On 19 February 2015 at 15:34, Alvaro Herrera alvhe...@2ndquadrant.com wrote: Juan Pablo L wrote: Hello, i have created a function (in C) that receives an array that contains tuples of ID's

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Alvaro Herrera
Juan Pablo L wrote: Hi, i want previous updates to rollback ... like nothing happened (a normal begin/rollback behaviour) Ah, so ereport() is exactly what you want, like Chris Mair said. Assuming you wrote it correctly, you should see the ERROR line in the server logs (set

Re: [GENERAL] rollback in C functions

2015-02-19 Thread John R Pierce
On 2/19/2015 1:41 PM, Juan Pablo L wrote: Hi, i want previous updates to rollback ... like nothing happened (a normal begin/rollback behaviour) so thrown an exception. The actual rollback has to be invoked by the client application program, which should catch the error thrown by the query

Re: [GENERAL] rollback in C functions

2015-02-19 Thread John R Pierce
On 2/19/2015 2:02 PM, Juan Pablo L wrote: Thank you Alvaro, i m afraid ereport seems to be the way, that it is complicated to catch this error code in the code of the caller. cause you have to use a callback etc etc a query that triggers ereport(ERROR,) should return a PGresult* that you

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
Thank you, i will try this, honestly i was checking if PGResult is NULL, when i trigger the exception i always get NULL so i did not any further but i will try this . On 19 February 2015 at 16:22, John R Pierce pie...@hogranch.com wrote: On 2/19/2015 2:02 PM, Juan Pablo L wrote: Thank you

Re: [GENERAL] rollback in C functions

2015-02-19 Thread Juan Pablo L
i tried this but the call to PQresultErrorField(PGresult, PG_DIAG_SQLSTATE) is returning NULL, this is what trigger the exception in the function code: ereport(ERROR,(errcode(ERRCODE_SQL_ROUTINE_EXCEPTION),errmsg(Plan with id %s does not allow balance with id %s,plan_id,in_balanceid))); and this