Re: COALESCE requires NULL from scalar subquery has a type - Mailing list pgsql-general

From Tom Lane
Subject Re: COALESCE requires NULL from scalar subquery has a type
Date
Msg-id 25091.1454942988@sss.pgh.pa.us
Whole thread Raw
In response to COALESCE requires NULL from scalar subquery has a type  (Geoff Winkless <pgsqladmin@geoff.dj>)
Responses Re: COALESCE requires NULL from scalar subquery has a type
List pgsql-general
Geoff Winkless <pgsqladmin@geoff.dj> writes:
> SELECT COALESCE((SELECT 'Yes' FROM gwtest WHERE id=4), 'No') AS valid;
> gives an error

> I'm guessing this is because Postgres can't deduce the type of the
> string column from the source when the result isn't returned. Oddly,
> it also seems to cope when I do:
> SELECT COALESCE((SELECT 'Yes'::varchar FROM gwtest WHERE id=4), 'No') AS valid

Yup.  The output column type of the sub-SELECT is determined without
reference to its context, so there's nothing causing the unknown-type
literal to get assigned a definite type.

There's been occasional discussion of changing that behavior, but it's
not real clear that it wouldn't create as many problems as it solves.

            regards, tom lane


pgsql-general by date:

Previous
From: Thom Brown
Date:
Subject: Very slow DELETEs with foreign keys
Next
From: Tom Lane
Date:
Subject: Re: Very slow DELETEs with foreign keys