A very Strange SQL of PostgreSQL
There is a Strange SQL in our PostgreSQL SERVER, version 8.4. It is looks like a system sql which excuted by PG server ! I have no idea about this sql? Anyone know this ?
--Strange sql
SELECT NULL AS TABLE_CAT,
n.nspname AS TABLE_SCHEM,
c.relname AS TABLE_NAME,
CASE n.nspname ~ '^pg_' OR n.nspname = 'information_schema'
WHEN true THEN
CASE
WHEN n.nspname = 'pg_catalog' OR n.nspname = 'information_schema' THEN
CASE c.relkind
WHEN 'r' THEN 'SYSTEM TABLE'
WHEN 'v' THEN 'SYSTEM VIEW'
WHEN 'i' THEN 'SYSTEM INDEX'
开发者_StackOverflow社区 ELSE NULL
END
WHEN n.nspname = 'pg_toast' THEN
CASE c.relkind
WHEN 'r' THEN 'SYSTEM TOAST TABLE'
WHEN 'i' THEN 'SYSTEM TOAST INDEX'
ELSE NULL
END
ELSE
CASE c.relkind
WHEN 'r' THEN 'TEMPORARY TABLE'
WHEN 'i' THEN 'TEMPORARY INDEX'
ELSE NULL
END
END
WHEN false THEN
CASE c.relkind
WHEN 'r' THEN 'TABLE'
WHEN 'i' THEN 'INDEX'
WHEN 'S' THEN 'SEQUENCE'
WHEN 'v' THEN 'VIEW'
ELSE NULL
END
ELSE NULL
END AS TABLE_TYPE,
d.description AS REMARKS
FROM pg_catalog.pg_namespace n,
pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid
AND d.objsubid = 0)
LEFT JOIN pg_catalog.pg_class dc ON (d.classoid = dc.oid
AND dc.relname='pg_class'
It is part of the getTables()
implementation in the postgresql JDBC driver.
Update
While Google Code Search was retired a few years after this answer was originally posted, you can see this logic today in the pgjdbc "meta data" sources.
This problem also occures when your application uses some connection manager like c3p0. C3P0 has option preferredTestQuery
which defines a query to be executed before acquiring a connection from pool of connection.
If you didn't set this option it would do some weird sql query, otherwise you can tell it to use preferredTestQuery=SELECT 1
精彩评论