From: Vik Fearing <vik.fearing@2ndquadrant.com>
To: Steven Winfield <Steven.Winfield@cantabcapital.com>
To: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: A little RULE help?
Date: Sat, 27 Jan 2018 02:26:55 +0100
Message-ID: <4e9b5b67-8966-4dfb-dcf9-6023c3b8fff1@2ndquadrant.com> (raw)
In-Reply-To: <E9FA92C2921F31408041863B74EE4C2001A478A720@CCPMAILDAG03.cantab.local>
References: <E9FA92C2921F31408041863B74EE4C2001A47847D0@CCPMAILDAG03.cantab.local>
<a607457c-e7af-5b93-c0c5-444805318da2@commandprompt.com>
<E9FA92C2921F31408041863B74EE4C2001A4784E8C@CCPMAILDAG03.cantab.local>
<e104e516-70b7-d035-50fa-11fae18160aa@commandprompt.com>
<E9FA92C2921F31408041863B74EE4C2001A478A720@CCPMAILDAG03.cantab.local>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: vik.fearing@2ndquadrant.com, Steven.Winfield@cantabcapital.com
Subject: Re: A little RULE help?
In-Reply-To: <4e9b5b67-8966-4dfb-dcf9-6023c3b8fff1@2ndquadrant.com>
References: <E9FA92C2921F31408041863B74EE4C2001A47847D0@CCPMAILDAG03.cantab.local> <a607457c-e7af-5b93-c0c5-444805318da2@commandprompt.com> <E9FA92C2921F31408041863B74EE4C2001A4784E8C@CCPMAILDAG03.cantab.local> <e104e516-70b7-d035-50fa-11fae18160aa@commandprompt.com> <E9FA92C2921F31408041863B74EE4C2001A478A720@CCPMAILDAG03.cantab.local> <4e9b5b67-8966-4dfb-dcf9-6023c3b8fff1@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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