Re: Rule system and unsucessful updates. - Mailing list pgsql-general

From Tom Lane
Subject Re: Rule system and unsucessful updates.
Date
Msg-id 17060.1137438366@sss.pgh.pa.us
Whole thread Raw
In response to Re: Rule system and unsucessful updates.  (Matthew Schumacher <matt.s@aptalaska.net>)
Responses Re: Rule system and unsucessful updates.  (Matthew Schumacher <matt.s@aptalaska.net>)
List pgsql-general
Matthew Schumacher <matt.s@aptalaska.net> writes:
> update test set id = 1, data = 'test';

The above is a pretty bad idea in any case --- think about what happens
when you have some data in the table.  It'll set *every row* to id = 1
and data = 'test'.  The reason nothing happens when there is nothing in
the table is that there is no row that can be updated.  Taking an action
"instead of" an action that doesn't happen still doesn't happen.

Any practical application using UPDATE is going to say UPDATE ... WHERE
to limit the set of rows that get changed, and what you have to think
about is whether you need a rule to do anything in that situation.

For what I think you want this application to do, it'd make more sense
for the application to say "INSERT some-data", and for you to have a
rule that changes that into an UPDATE if there is a pre-existing row
with matching key columns.

            regards, tom lane

pgsql-general by date:

Previous
From: Matthew Schumacher
Date:
Subject: Re: Rule system and unsucessful updates.
Next
From: Emi Lu
Date:
Subject: lists all users under groups