0

I am trying to figure out the source system which are populating a particular table in pg admin.

Can i do it with information_schema or pg_proc I tried but i don't know exact query. can anyone help me?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
infa
  • 69
  • 1
  • 2
  • 11

1 Answers1

0

There is a nice trick, how to get a complete queries to system catalog.

Run psql with option -E. It means echo all. Then psql shows all statements generated by backslash psql commands (like \df for list of functions):

[pavel@localhost plpgsql_check]$ psql -E postgres
psql (9.5devel)
Type "help" for help.

postgres=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
  c.relname as "Name",
  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' END as "Type",
  pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
      AND n.nspname  'pg_catalog'
      AND n.nspname  'information_schema'
      AND n.nspname !~ '^pg_toast'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************

So you have to know a backslash statements - some basic list:

  • \dt - list of tables
  • \df - list of functions
  • \dn - list of schemas
  • \l - list of databases
  • \? - list of backslash statements
Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94