From: Tom Lane <tgl@sss.pgh.pa.us>
To: Александр <alexander_8901@mail.ru>
Cc: pgsql-bugs@postgresql.org
Subject: Re: bug in RULE insert
Date: Fri, 09 Dec 2016 10:25:37 -0500
Message-ID: <16622.1481297137@sss.pgh.pa.us> (raw)
In-Reply-To: <1481285920.491235434@f66.i.mail.ru>
References: <1481285920.491235434@f66.i.mail.ru>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
=?UTF-8?B?0JDQu9C10LrRgdCw0L3QtNGA?= <alexander_8901@mail.ru> writes:
> Strange the rule works for an insertion
This is expected behavior, because the rule works like a macro, and
you have a volatile argument (that is, the nextval() call for the
serial column's default) being passed to it and thereby being executed
twice. IOW, what you wrote is equivalent to
insert into test(id, name)
values
(nextval('test_id_seq'), '1'),
(nextval('test_id_seq'), '2'),
(nextval('test_id_seq'), '3');
and that executes, then the rule causes this to also be executed:
insert into v_test (v_id, v_name)
values
(nextval('test_id_seq'), '1'),
(nextval('test_id_seq'), '2'),
(nextval('test_id_seq'), '3');
What you seem to want would be much more reliably done with a trigger.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, alexander_8901@mail.ru
Subject: Re: bug in RULE insert
In-Reply-To: <16622.1481297137@sss.pgh.pa.us>
References: <1481285920.491235434@f66.i.mail.ru> <16622.1481297137@sss.pgh.pa.us>
* 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