views:

38

answers:

2

I am new to PostgreSQL and I searched high and low but cannot find an answer to this question

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

I went on 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);

Psql process returns:

INSERT 0 1

what does this line mean? beside 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 return and 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: yes, the insertion was done without errors

or

no, the "0 1" means something that 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.

Thanks!

A: 

Annoyingly enough, I can't find any actual documentation about this.

However looking at http://www.postgresql.org/docs/8.4/interactive/rules-status.html and PQcmdStatus within http://www.postgresql.org/docs/8.4/interactive/libpq-exec.html, it appears that what you are seeing is a command status.

The format I'm inferring from the documentation is COMMAND STATUS_CODE ROWS AFFECTED.

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

So in other words, your command is completing successfully!

SamStephens
outstanding, thank you, I subsequently determined that. I mean if I see the data in phpPGsql admin... I had to assume it was working. @matthew: that tip on returning the primary id key is very useful... I do have one, though it is name "donation_id" and is auto incremented via an associated sequence.
katir
+5  A: 

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.

Milen A. Radev
As an addendum to this answer, assuming you have a field called "id" in your table that is auto-assigned via sequence, if you run your insert in the form "INSERT INTO new-table (first_name, last_name, anonymous) VALUES ('batman', 'Moonboy', TRUE) RETURNING id", the message "INSERT 0 1" would be replaced by the new value of id in the just-inserted record.
Matthew Wood