Skip site navigation (1) Skip section navigation (2)

Re: Confused about CASE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: Thomas Kellerer <spam_eater(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Confused about CASE
Date: 2008-03-01 02:04:17
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> writes:
> It looks like the problem is that relkind is of the somewhat odd
> PostgreSQL type "char" not an actual char(1), so with the else in there it
> appears to try to force the unknown literals into that type which only
> takes the first character. It will probably work if you cast in the else,
> like "else CAST(c.relkind as CHAR(1))".

Right, the problem is that all the string literals are "unknown" and
don't force a type decision, so the "char" type gets chosen as the
result type of the CASE, and then the literals get coerced to that.

If you explicitly cast any one of the CASE output expressions to text
--- either relkind, or any of the constants --- the behavior is as the
OP expects.

			regards, tom lane

In response to

pgsql-general by date

Next:From: Tom LaneDate: 2008-03-01 02:17:46
Subject: Re: Querying Headers
Previous:From: Scott MarloweDate: 2008-03-01 01:29:03
Subject: Re: SERIAL and Primary Key

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group