Re: Avoid casting NULLs in UNION...

From: Marko Rihtar <rihtar(dot)marko(at)gmail(dot)com>
To: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Avoid casting NULLs in UNION...
Date: 2013-02-04 07:55:17
Message-ID: CABSSDoHkQnYRP8yK6p5DDrnF6vo5H56Csw=0suuNsZqJ7acrjA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

OK Albe,

thanks for info

2013/2/1 Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>

> Marko Rihtar wrote:
> > maybe you can help me with this issue.
> > Here is an example
> >
> > SELECT NULL::integer
> > UNION ALL
> > SELECT NULL
> > UNION ALL
> > SELECT 123
> >
> > For this sql to work i have to cast NULL to integer.
> > I was wondering if there exists some configuration parameter at database
> level that can be used to
> > avoid this need for explicit casting?
>
> Not that I know of.
>
> The behaviour is well defined and documented, see
> http://www.postgresql.org/docs/current/static/typeconv-union-case.html
>
> The UNIONs are computed left to right,
> and the data type in the first UNION resolves to "text"
> according to rule 2 of the page given above.
>
> You can reorder the UNIONs or use parentheses.
>
> Yours,
> Laurenz Albe
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message CS DBA 2013-02-05 01:49:11 SSL question
Previous Message Dave Manginelli 2013-02-04 01:51:07 SSPI Authentication on Windows 2012 (for Win. Clients)