Re: Rule system and unsucessful updates.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Matthew Schumacher <matt(dot)s(at)aptalaska(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Rule system and unsucessful updates.
Date: 2006-01-16 19:06:06
Message-ID: 17060.1137438366@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Matthew Schumacher <matt(dot)s(at)aptalaska(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Emi Lu 2006-01-16 19:43:49 lists all users under groups
Previous Message Matthew Schumacher 2006-01-16 18:47:25 Re: Rule system and unsucessful updates.