> I wanted to use the following statement to "translate" the relkind
> column to a
> more descriptive value:
> select c.relname
> when c.relkind in ('t','r') then 'table'
> when c.relkind = 'i' then 'index'
> when c.relkind = 'S' then 'sequence'
> when c.relkind = 'v' then 'view'
> else c.relkind
> end as mykind
> from pg_class c
> The idea is that for anything else than 't', 'r', 'i', 'S' or 'v' it
> simply return the value of relkind. In the other cases I want "my"
> But for some reason this returns the value of relkind for all rows.
> When I
> remove the "else c.relkind" part, it works as expected.
I agree, this seems confusing. I found a section of the doc that caught my
"The data types of all the result expressions must be convertible to a
single output type."
Which led me to try this, which works:
when c.relkind in ('t','r') then 'table'
when c.relkind = 'i' then 'index'
when c.relkind = 'S' then 'sequence'
when c.relkind = 'v' then 'view'
end as mykind
from pg_class c
In response to
pgsql-general by date
|Next:||From: Stephan Szabo||Date: 2008-03-01 00:00:17|
|Subject: Re: Confused about CASE|
|Previous:||From: Thomas Kellerer||Date: 2008-02-29 23:42:36|
|Subject: Confused about CASE|