PostgreSQL 一个很奇怪的SQL
我们的 PostgreSQL 服务器版本 8.4 中有一个奇怪的 SQL。它看起来像是由PG服务器执行的系统sql!我不知道这个sql?有人知道这个吗?
--奇怪的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'
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'
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'
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是 postgresql JDBC 驱动程序中
getTables()
实现的一部分。更新
虽然 Google 代码搜索在该答案最初发布几年后就已停用,但您今天可以在 pgjdbc“元数据”源。
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.
当您的应用程序使用某些连接管理器(例如 c3p0)时,也会出现此问题。 C3P0 有选项preferredTestQuery,它定义在从连接池获取连接之前要执行的查询。
如果您没有设置此选项,它将执行一些奇怪的 sql 查询,否则您可以告诉它使用
preferredTestQuery=SELECT 1
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