Re: COALESCE requires NULL from scalar subquery has a type

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Geoff Winkless <pgsqladmin(at)geoff(dot)dj>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: COALESCE requires NULL from scalar subquery has a type
Date: 2016-02-09 14:53:02
Message-ID: 5636.1455029582@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Geoff Winkless <pgsqladmin(at)geoff(dot)dj> writes:
> I'm not asking that it coerce an actual value with a genuinely unknown
> type to a text value: I'm simply suggesting that it's unnecessary for
> COALESCE to coerce an unknown-typed NULL into anything (even if you
> ignore that NULL is, as far as I know, equivalent, no matter what its
> type), because as far as COALESCE is concerned the NULL can be
> instantly ignored.

Leaving aside the question of whether that is actually feasible or
a good idea: how would that improve your original complaint?

SELECT COALESCE((SELECT 'Yes' FROM gwtest WHERE id=4), 'No') AS valid;

There's no null visible anywhere in that. I suppose that if there's
no row with id=4, there would be a null at runtime, but that's not
going to make any difference for parse-time determination of what
type the COALESCE() will return.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Geoff Winkless 2016-02-09 14:56:53 Re: COALESCE requires NULL from scalar subquery has a type
Previous Message David G. Johnston 2016-02-09 14:43:37 Re: execute same query only one time?