Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Do PostgreSQL INSERT confirmation params mean?

In my LiveCode Server app I'm getting a dberr returned on insertion but no explicit error code.

I went on a terminal and did the insertion by hand as user Postgres.

%My_Dbase=# INSERT INTO new-table (first_name, last_name, anonymous) VALUES ('batman', 'Moonboy', TRUE); 

The psql process returns:

INSERT 0 1 

What does this line mean? Besides the primary table I also have a sequence to increment the primary key ID (int) of the main table.

If I check the data, the data is inserted, the primary key is increment by one and everything seems fine, I'm not sure why my app is returning an error (could be a bug in the app or my code).

But if I knew what INSERT 0 1 meant, that would help me assure myself that:

  1. Yes, the insertion was done without errors, or
  2. No, the 0 1 indicates an error of some sort.

If anyone has a link to the PostgreSQL doc which tells what these server response params are, I will study it... I have looked everywhere.

like image 759
katir Avatar asked Sep 30 '10 22:09

katir


People also ask

What does Postgres return on insert?

In an INSERT , the data available to RETURNING is the row as it was inserted. This is not so useful in trivial inserts, since it would just repeat the data provided by the client. But it can be very handy when relying on computed default values.

How many INSERTs can Postgres handle per second?

Single row INSERTs In the same region on AWS with lets say 1ms latency, this number can go up to ~500 INSERTs per second.

What is needed for an insert on conflict update to work?

You must have INSERT privilege on a table in order to insert into it. If ON CONFLICT DO UPDATE is present, UPDATE privilege on the table is also required. If a column list is specified, you only need INSERT privilege on the listed columns.

Does Postgres preserve insertion order?

The answer for this simple case is: "Yes".


2 Answers

Excerpt from the relevant page in the manual:

Outputs

On successful completion, an INSERT command returns a command tag of the form

INSERT oid count

The count is the number of rows inserted. If count is exactly one, and the target table has OIDs, then oid is the OID assigned to the inserted row. Otherwise oid is zero.

like image 146
Milen A. Radev Avatar answered Sep 20 '22 13:09

Milen A. Radev


EDIT: I've been pointed at the documentation for this, https://www.postgresql.org/docs/14/protocol-message-formats.html

The format is COMMAND OID ROWS.

As OIDs system columns are not supported anymore, OID is always zero.

So what you are seeing is that you've done an insert, the OID was zero, and one row was inserted.

So in other words, your command is completing successfully!

like image 43
SamStephens Avatar answered Sep 20 '22 13:09

SamStephens