Greenplum查看psql操作执行的具体语句

2021-03-19 10:27:16 浏览数 (1)

有时候,这可以作为一种参考的方向,查看psql命令行如何获取结果。

我们在用psql登陆时,增加-E选项即可,示例如下:

代码语言:javascript复制
postgres=# d  test_table
********* QUERY **********
SELECT c.oid,
  n.nspname,
  c.relname
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relname ~ '^(test_table)$'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 2, 3;
**************************

********* QUERY **********
select oid from pg_catalog.pg_class where relnamespace = 11 and relname  = 'pg_attribute_encoding'
**************************

********* QUERY **********
SELECT relchecks, relkind, relhasindex, relhasrules, reltriggers <> 0, relhasoids, pg_catalog.array_to_string(reloptions, E', '), reltablespace, relstorage
FROM pg_catalog.pg_class WHERE oid = '33410'
**************************

********* QUERY **********
SELECT a.attname,
  pg_catalog.format_type(a.atttypid, a.atttypmod),
  (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)
   FROM pg_catalog.pg_attrdef d
   WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),
  a.attnotnull, a.attnum,
  a.attstorage ,
  pg_catalog.col_description(a.attrelid, a.attnum)
FROM pg_catalog.pg_attribute a
LEFT OUTER JOIN pg_catalog.pg_attribute_encoding e
ON   e.attrelid = a .attrelid AND e.attnum = a.attnum
WHERE a.attrelid = '33410' AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
**************************

********* QUERY **********
SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, i.indisvalid, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
  null AS constraintdef, null AS contype, false AS condeferrable, false AS condeferred, c2.reltablespace
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
WHERE c.oid = '33410' AND c.oid = i.indrelid AND i.indexrelid = c2.oid
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname
**************************

********* QUERY **********
SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '33410' ORDER BY inhseqno
**************************

********* QUERY **********
SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '33410' ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;
**************************

********* QUERY **********
SELECT attrnums
FROM pg_catalog.gp_distribution_policy t
WHERE localoid = '33410'
**************************

********* QUERY **********
SELECT attname FROM pg_attribute
WHERE attrelid = '33410'
AND attnum = '2'
**************************

********* QUERY **********
SELECT parrelid FROM pg_catalog.pg_partition WHERE parrelid = '33410'
**************************

********* QUERY **********
WITH att_arr AS (SELECT unnest(paratts)
	FROM pg_catalog.pg_partition p
	WHERE p.parrelid = '33410' AND p.parlevel = 0 AND p.paristemplate = false),
idx_att AS (SELECT row_number() OVER() AS idx, unnest AS att_num FROM att_arr)
SELECT attname FROM pg_catalog.pg_attribute, idx_att
	WHERE attrelid='33410' AND attnum = att_num ORDER BY idx

0 人点赞