pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Dean Rasheed <dean.a.rasheed@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17803: Rule "ALSO INSERT ... SELECT ..." fails to substitute default values
Date: Wed, 22 Feb 2023 15:00:00 +0300
Message-ID: <60780f8c-3132-133e-8286-538b732bff19@gmail.com> (raw)
In-Reply-To: <CAEZATCUrXMUK8F6daS_f0kH7o_=nDtEqA1Ny23SwHWbFvH61PA@mail.gmail.com>
References: <17803-53c63ed4ecb4eac6@postgresql.org>
	<CAEZATCUQtGx6gQtryMbC3ZsEd4GUcc5THVnkXP1F0Fan_uLG-Q@mail.gmail.com>
	<3953951.1676991950@sss.pgh.pa.us>
	<CAEZATCWoXX9-+ZaaLiOMRsZgwmStayBGmCdA0BdwVzo5GCU51Q@mail.gmail.com>
	<3977948.1677002558@sss.pgh.pa.us>
	<7f8f1bbb-9fb3-80fb-a400-5c7e755b5aa2@gmail.com>
	<CAEZATCUrXMUK8F6daS_f0kH7o_=nDtEqA1Ny23SwHWbFvH61PA@mail.gmail.com>

22.02.2023 12:07, Dean Rasheed wrote:
> On Wed, 22 Feb 2023 at 08:00, Alexander Lakhin <exclusion@gmail.com> wrote:
>> I have a minor question about the condition:
>> +                if (pt->commandType == CMD_INSERT ...
>> Is it possible to get another commandType there?
> Yes, there could also be ON INSERT DO ALSO UPDATE/DELETE rules. The
> new code is intended to apply only for DO ALSO INSERT .. SELECT rules
> (where the VALUES RTE in "pt" isn't in the usual place), but other
> types of command in the rule are also possible. As long as the
> top-level command is a multi-row INSERT ... VALUES (), (), ... it can
> reach this code block.

Thanks! I understand this place better now.
I mistakenly supposed that VALUES RTE can intervene with INSERT only.
But while exploring how they can affect other statements,
I've found one more interesting thing:
CREATE TABLE t (a int, b int DEFAULT -1);
CREATE VIEW v AS SELECT * FROM t;
CREATE RULE vr AS ON INSERT TO v DO ALSO INSERT INTO t SELECT NEW.b;
INSERT INTO v VALUES(10, -1), (20, DEFAULT);
SELECT * FROM v;

  a  | b
----+----
  10 | -1
  20 | -1
  -1 | -1
     | -1

It seems that a NEW field filled correctly if it is not DEFAULT,
but DEFAULT is lost somehow.

Best regards,
Alexander





view thread (17+ messages)  latest in thread

Message-ID: <60780f8c-3132-133e-8286-538b732bff19@gmail.com>
Permalink:  ../60780f8c-3132-133e-8286-538b732bff19@gmail.com/
Also on:    postgresql.org/message-id/60780f8c-3132-133e-8286-538b732bff19@gmail.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com, dean.a.rasheed@gmail.com, tgl@sss.pgh.pa.us, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17803: Rule "ALSO INSERT ... SELECT ..." fails to substitute default values
  In-Reply-To: <60780f8c-3132-133e-8286-538b732bff19@gmail.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