postgresql 技巧

发布: 2007-12-14 10:46

将数组当结果集使用:  


SELECT arr[i]

   FROM

      generate_series(1, 4) AS i,

      string_to_array('1,6,3,4', ',') AS arr;


 


用SQL获取postgreSQL表结构


SELECT

attname,typname,adsrc

     FROM

           pg_attribute

           INNER JOIN pg_class  ON pg_attribute.attrelid = pg_class.oid

           INNER JOIN pg_type   ON pg_attribute.atttypid = pg_type.oid

           LEFT OUTER JOIN pg_attrdef ON pg_attrdef.adrelid = pg_class.oid AND pg_attrdef.adnum = pg_attribute.attnum

           LEFT OUTER JOIN pg_description ON pg_description.objoid = pg_class.oid AND pg_description.objsubid = pg_attribute.attnum

     WHERE

           pg_attribute.attnum > 0

          AND attisdropped <> 't'

           AND pg_class.relname= 'cube_os'

     ORDER BY pg_attribute.attnum ;



原文: http://qtchina.tk/?q=node/109

Powered by zexport