Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the result output after a PostgreSQL insert mean exactly?

Tags:

postgresql

I am inserting data into a PostgreSQL database. I do something like this:

$ psql test -c "insert into items (name) values ('test name') returning id " -At
4
INSERT 0 1

What does the first number in INSERT 0 1 refer to? I assume the second number is the number of rows affected or created.

like image 862
dan Avatar asked Dec 14 '22 18:12

dan


1 Answers

It's the "command tag". And the guy that was quoted here answering on the pgsql general list list didn't give credit when he quoted directly from the manual:

For an INSERT command, the tag is INSERT oid rows, where rows is the number of rows inserted. oid used to be the object ID of the inserted row if rows was 1 and the target table had OIDs, but OIDs system columns are not supported anymore; therefore oid is always 0.

(Updated quote for Postgres 14.)

like image 71
Erwin Brandstetter Avatar answered May 11 '23 11:05

Erwin Brandstetter