PostgreSQL 一个很奇怪的SQL

发布于 2024-10-27 07:50:26 字数 1839 浏览 0 评论 0原文

我们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

追我者格杀勿论 2024-11-03 07:50:26

它是 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.

星星的轨迹 2024-11-03 07:50:26

当您的应用程序使用某些连接管理器(例如 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文