Re: domain cast in parameterized vs. non-parameterized query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: David Kamholz <lautgesetz(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: domain cast in parameterized vs. non-parameterized query
Date: 2017-12-21 14:19:16
Message-ID: 11221.1513865956@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> 2017-12-20 23:41 GMT+01:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> Hm, scratch that --- experimentation shows that the parser still produces
>> a CoerceToDomain node in that case, not a literal of the domain type.

> Why the rewrite doesn't reduce it? Or why parser does it?

Because ALTER DOMAIN can change what would be a valid value.

regression=# create domain myd as int;
CREATE DOMAIN
regression=# create view v1 as select 0::myd as c1;
CREATE VIEW
regression=# select * from v1;
c1
----
0
(1 row)

regression=# alter domain myd add check (value > 0);
ALTER DOMAIN
regression=# select * from v1;
ERROR: value for domain myd violates check constraint "myd_check"

If the view's expression had been reduced to just a Const when it
was stored, we'd not notice that the value is no longer valid for
the domain. So CoerceToDomain is always postponed till runtime.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-12-21 14:22:36 Re: Reproducible builds: genbki.pl and Gen_fmgrtab.pl
Previous Message Alvaro Herrera 2017-12-21 14:18:03 Re: Reproducible builds: genbki.pl and Gen_fmgrtab.pl