Take the 2-minute tour ×

My database driver for PostgreSQL 8/9 does not return a count of records affected when executing INSERT or UPDATE.

PostgreSQL offers the non-standard syntax "RETURNING" which seems like a good workaround. But what might be the syntax? The example returns the ID of a record, but I need a count.

INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets') RETURNING did;

share|improve this question
I know it doesn't sound helpful but you have to find better drivers or update for your current ones (the solution OMG Ponies have posted works only in PL/pgSQL code). –  Milen A. Radev Oct 28 '10 at 6:42
add comment

1 Answer

I agree w/ Milen, your driver should do this for you. What driver are you using and for what language? But if you are using plpgsql, you can use GET DIAGNOSTICS my_var = ROW_COUNT;


share|improve this answer
add comment

Your Answer


