Tricky query, tricky response - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Tricky query, tricky response
Date
Msg-id Pine.LNX.4.10.9910010253310.625-100000@peter-e.yi.org
Whole thread Raw
Responses Re: [HACKERS] Tricky query, tricky response  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
As you might recognize, this is supposed to be a psql \d imitation in one 
shot:

SELECT usename as "Owner", relname as "Relation",
(CASE WHEN relkind='r' THEN (CASE WHEN 0<(select count(*) from pg_views where viewname = relname)THEN 'view' ELSE
'table'END)           WHEN relkind='i' THEN 'index'     WHEN relkind='S' THEN 'sequence'     ELSE 'other'
 
END) as "Type"
FROM pg_class, pg_user
WHERE usesysid = relowner AND
( relkind = 'r' OR relkind = 'i' OR relkind = 'S') AND
relname !~ '^pg_' AND
(relkind != 'i' OR relname !~ '^xinx')  ORDER BY relname;
ERROR:  flatten_tlistentry: Cannot handle node type 108

However, if you do 
-    (CASE WHEN 0<(select count(*) from pg_views where viewname = relname)
-    THEN 'view' ELSE 'table' END)      
+    'relation'
if works fine. No nested CASE's?

PostgreSQL 6.5.2 on i586-pc-linux-gnu, compiled by egcs

-- 
Peter Eisentraut - peter_e@gmx.net
http://yi.org/peter-e



pgsql-hackers by date:

Previous
From: "Jackson, DeJuan"
Date:
Subject: testing unsubscribe
Next
From: Roland Roberts
Date:
Subject: Re: [HACKERS] Re: TO_CHAR()