Re: Assignment of valid collation for SET operations on queries with UNKNOWN types.

From: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Rahila Syed <rahilasyed90(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Assignment of valid collation for SET operations on queries with UNKNOWN types.
Date: 2017-01-24 13:28:21
Message-ID: CAFjFpRds1+L1Ljyexz6hH_AVD7DF31Aer6qejY5LuJWZGYORkA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jan 23, 2017 at 9:56 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I wrote:
>> Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com> writes:
>>> UNKNOWN is not exactly a pseudo-type.
>
>> Well, as I said to Michael just now, I think we should turn it into one
>> now that we're disallowing it in tables, because "cannot be used as a
>> table column" is more or less the definition of a pseudotype.
>
> I experimented with this, and it actually doesn't seem to be any harder
> than the attached: there's one type_sanity query that changes results,
> and otherwise all the regression tests pass.
>
> I've grepped the code for references to UNKNOWNOID and TYPTYPE_PSEUDO,
> and I can't find any places where the behavior would change in a way
> that we don't want. Basically it looks like we'd disallow UNKNOWN as
> a domain base, a PL function argument or result, and a plpgsql local
> variable; and all of those seem like good things from here.

Thanks. I think this brings unknown in line with record, internal,
void etc. and that's good. That's really where it should be.

I thought this code in CreateCast would create problem.

/* No pseudo-types allowed */
if (sourcetyptype == TYPTYPE_PSEUDO)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("source data type %s is a pseudo-type",
TypeNameToString(stmt->sourcetype))));

if (targettyptype == TYPTYPE_PSEUDO)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("target data type %s is a pseudo-type",
TypeNameToString(stmt->targettype))));

This means that the user can not create a cast to or from unknown
type. But then there's following code in can_coerce_type()
/*
* If input is an untyped string constant, assume we can convert it to
* anything.
*/
if (inputTypeId == UNKNOWNOID)
continue;
which would allow any kind of cast. But in coerce_type(), we seem to
handle case of unknown constants explicitly. But I think with the
earlier patch, we will be left with only the constant literals of
unknown type. So, we are fine. But I think we will have to watch for
any such casts created by users in pg_dump and pg_upgrade. Similarly
for transforms, range(?).

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2017-01-24 13:33:52 Re: Online enabling of page level checksums
Previous Message Stephen Frost 2017-01-24 13:22:14 Re: Checksums by default?