Wagener, Johannes J wrote:
> Hi Jeroen and Everyone,
> 
> I'm hoping that someone can explain this to me.
> 
> When I try to update a row that does not exist in a table (the table is 
> empty as a matter of fact), the query does not fail -   Instead it 
> executes successfully but obviously the row still does not exist and 
> therefore the query does nothing. 
> 
> When running the query from a program the "result::affected_rows()" 
> function returns 0.  I get the same result when running the query from 
> the command line.
> 
> Should the query not fail?  Surely trying to update a row that does not 
> exist should result in some type of error?  In DB2 the query will return 
> a "not found" error code as the row you are trying to update does not 
> exist.  (obviously Postgre is not DB2).
> 
> Anyone else come across this?
> 
> I suppose it's not such a big deal - but it does raise some questions 
> about the inner workings of the DBMS though.  

This really is standard SQL behaviour. An UPDATE is simply a SELECT 
followed by a manipulation of the selected records. And just like a 
SELECT can return 0 rows without returning an error, an UPDATE can 
affect 0 rows without returning an error.

There are a number of DBMSes that do raise an "error" if the number of 
rows returned by a SELECT is 0, and apparently DB2 even does this for 
UPDATEs. This is largely a matter of style, as it's not clear that a 
0-row SELECT or UPDATE is really an error.

BTW, the short form of PostgreSQL is "Postgres", not "Postgre". ;-)

--Bart
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to