From: | Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com> |
---|---|
To: | Steven Winfield <Steven(dot)Winfield(at)cantabcapital(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: A little RULE help? |
Date: | 2018-01-27 01:26:55 |
Message-ID: | 4e9b5b67-8966-4dfb-dcf9-6023c3b8fff1@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 01/26/2018 04:19 PM, Steven Winfield wrote:
> Back to my original attempt at writing an UPDATE rule…
>
> CREATE RULE rule_test_update AS ON UPDATE TO rule_test_view DO INSTEAD (
>
> UPDATE rule_test SET tt = tstzrange(lower(tt),
> CURRENT_TIMESTAMP, '[)') WHERE id = OLD.id;
>
> INSERT INTO rule_test (tt, foo, bar) VALUES
> (tstzrange(CURRENT_TIMESTAMP, NULL, '[)'), NEW.foo, NEW.bar) RETURNING *;
>
> );
>
> …I wondered whether the pseudo relations NEW and OLD were somehow being
> modified by the first command (the UPDATE), such that the second command
> (INSERT) could not function properly.
No. It's because your view's WHERE clause is being added to your INSERT
and of course nothing matches, so nothing gets inserted.
> That would fit with what I observe, but I’m not sure how I go about
> proving
EXPLAIN
> or fixing it.
Don't use RULEs.
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support
From | Date | Subject | |
---|---|---|---|
Next Message | support-tiger | 2018-01-28 00:34:51 | Re: pg 10.1 missing libpq in postgresql-devel |
Previous Message | David G. Johnston | 2018-01-26 17:08:07 | Re: Information on savepoint requirement within transctions |