Skip to content

Instantly share code, notes, and snippets.

@rbuels
Created October 16, 2009 18:23
Show Gist options
  • Select an option

  • Save rbuels/211943 to your computer and use it in GitHub Desktop.

Select an option

Save rbuels/211943 to your computer and use it in GitHub Desktop.
SELECT
rn AS name
, array_to_string( schemas, ', ') AS schemas
FROM ( SELECT
relname AS rn
, relkind
, array( SELECT nspname
|| ' ('
||(CASE WHEN relkind='r' THEN 'table'
WHEN relkind='v' THEN 'view'
WHEN relkind='i' THEN 'index'
WHEN relkind='S' THEN 'sequence'
ELSE relkind::text
END
)
|| ')'
FROM pg_class AS c_inner
JOIN pg_namespace n ON n.oid = c_inner.relnamespace
WHERE c_inner.relname = c.relname
)
AS schemas
FROM pg_class c
GROUP BY relname, relkind
) as rel_list
WHERE array_dims(schemas) <> '[1:1]'
ORDER BY relkind desc, name
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment