pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedquestion on UPDATE rules
3+ messages / 3 participants
[nested] [flat]
* question on UPDATE rules
@ 2000-04-22 00:33 Matthew Denny <mdenny@CS.Berkeley.EDU>
2000-04-22 10:02 ` Re: question on UPDATE rules Jan Wieck <wieck@debis.com>
2000-04-23 00:06 ` Re: question on UPDATE rules Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 2 replies; 3+ messages in thread
From: Matthew Denny @ 2000-04-22 00:33 UTC (permalink / raw)
To: pgsql-sql
I have a rule defined as the following:
CREATE RULE fooBar AS ON
UPDATE TO VectorMessageTable WHERE new.acks = (SELECT
numReplicas FROM VectorTable vt WHERE vt.ID =
new.ID) DO (DELETE FROM VectorMessageTable WHERE ID = new.ID AND
versionNum = new.versionNum);
if I call:
UPDATE VectorMessageTable SET acks =
<corresponding-numReplicas-from-VectorTable>
Then I the update goes through, but none of the records are
deleted. However, if I run any other subsequent update on these tuples in
VectorMessageTable (even ones that change the acks value) then the
rule fires and the tuples are deleted. The crux of the problem seems
to be that the "new" pseudo-relation seems to be returning old values,
as this is the only way I can explain this behavior. Has anyone else
experienced this problem? If so, a workaround would be greatly
appreciated.
thanks,
Matt Denny
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: question on UPDATE rules
2000-04-22 00:33 question on UPDATE rules Matthew Denny <mdenny@CS.Berkeley.EDU>
@ 2000-04-22 10:02 ` Jan Wieck <wieck@debis.com>
1 sibling, 0 replies; 3+ messages in thread
From: wieck@debis.com @ 2000-04-22 10:02 UTC (permalink / raw)
To: Matthew Denny <mdenny@CS.Berkeley.EDU>; +Cc: pgsql-sql
>
> I have a rule defined as the following:
>
> CREATE RULE fooBar AS ON
> UPDATE TO VectorMessageTable WHERE new.acks = (SELECT
> numReplicas FROM VectorTable vt WHERE vt.ID =
> new.ID) DO (DELETE FROM VectorMessageTable WHERE ID = new.ID AND
> versionNum = new.versionNum);
>
> if I call:
>
> UPDATE VectorMessageTable SET acks =
> <corresponding-numReplicas-from-VectorTable>
>
> Then I the update goes through, but none of the records are
> deleted. However, if I run any other subsequent update on these tuples in
> VectorMessageTable (even ones that change the acks value) then the
> rule fires and the tuples are deleted. The crux of the problem seems
> to be that the "new" pseudo-relation seems to be returning old values,
> as this is the only way I can explain this behavior. Has anyone else
> experienced this problem? If so, a workaround would be greatly
> appreciated.
Sorry, but I haven't understood what you really want the rule
to do. Maybe you can give me enought of your schema plus
some sample queries with comments what you want the rule then
to do.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#========================================= wieck@debis.com (Jan Wieck) #
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: question on UPDATE rules
2000-04-22 00:33 question on UPDATE rules Matthew Denny <mdenny@CS.Berkeley.EDU>
@ 2000-04-23 00:06 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lane @ 2000-04-23 00:06 UTC (permalink / raw)
To: Matthew Denny <mdenny@CS.Berkeley.EDU>; +Cc: pgsql-sql
Matthew Denny <mdenny@CS.Berkeley.EDU> writes:
> I have a rule defined as the following:
> CREATE RULE fooBar AS ON
> UPDATE TO VectorMessageTable WHERE new.acks = (SELECT
> numReplicas FROM VectorTable vt WHERE vt.ID =
> new.ID) DO (DELETE FROM VectorMessageTable WHERE ID = new.ID AND
> versionNum = new.versionNum);
> if I call:
> UPDATE VectorMessageTable SET acks =
> <corresponding-numReplicas-from-VectorTable>
> Then I the update goes through, but none of the records are
> deleted. However, if I run any other subsequent update on these tuples in
> VectorMessageTable (even ones that change the acks value) then the
> rule fires and the tuples are deleted.
Not sure, but maybe you want DO INSTEAD DELETE ... rather than just
DO DELETE ... ? As it stands, you're commanding the machine to both
delete and update the tuples for which the rule fires. I think that
will result in the old tuple being marked deleted (twice!), but the
update will still produce a new tuple that's not marked deleted.
That seems to match your symptoms...
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2000-04-23 00:06 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-04-22 00:33 question on UPDATE rules Matthew Denny <mdenny@CS.Berkeley.EDU>
2000-04-22 10:02 ` Jan Wieck <wieck@debis.com>
2000-04-23 00:06 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox