Re: polymorphic SQL functions has a problem with domains

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Johnston <polobo(at)yahoo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: polymorphic SQL functions has a problem with domains
Date: 2014-04-02 16:32:30
Message-ID: 20140402163230.GP3750@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2014-04-02 12:27:30 -0400, Tom Lane wrote:
> David Johnston <polobo(at)yahoo(dot)com> writes:
> > Does something like:
> > SELECT ($1 + $2)::$1%TYPE
> > exist where you can explicitly cast to the type of the input argument?
>
> I don't think SQL-language functions have such a notation, but it's
> possible in plpgsql, if memory serves.

Sometimes you can play nasty tricks using COALESCE() to force a cast
like that.
E.g. SELECT COALESCE(NULLIF($1, $1), $1 + $2);

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Johnston 2014-04-02 16:34:15 Re: polymorphic SQL functions has a problem with domains
Previous Message Pavel Stehule 2014-04-02 16:30:30 Re: polymorphic SQL functions has a problem with domains