Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual schemas and tables for psql commands #39

Open
kezhuw opened this issue Dec 11, 2024 · 0 comments
Open

Virtual schemas and tables for psql commands #39

kezhuw opened this issue Dec 11, 2024 · 0 comments
Labels
P0 Priority Level 0

Comments

@kezhuw
Copy link
Owner

kezhuw commented Dec 11, 2024

\l

SQL: SELECT
  d.datname as "Name",
  pg_catalog.pg_get_userbyid(d.datdba) as "Owner",
  pg_catalog.pg_encoding_to_char(d.encoding) as "Encoding",
  'libc' AS "Locale Provider",
  d.datcollate as "Collate",
  d.datctype as "Ctype",
  NULL as "ICU Locale",
  NULL as "ICU Rules",
  pg_catalog.array_to_string(d.datacl, E'\n') AS "Access privileges"
FROM pg_catalog.pg_database d
ORDER BY 1;

\dt

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 't' THEN 'TOAST table' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'partitioned table' WHEN 'I' THEN 'partitioned index' 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','p','')
      AND n.nspname <> 'pg_catalog'
      AND n.nspname !~ '^pg_toast'
      AND n.nspname <> 'information_schema'
  AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;

See:

  1. https://www.atlassian.com/data/admin/how-to-list-databases-and-tables-in-postgresql-using-psql
  2. https://www.postgresql.org/docs/current/app-psql.html
@kezhuw kezhuw added the P0 Priority Level 0 label Dec 12, 2024
@kezhuw kezhuw added this to SeamDB Dec 16, 2024
@kezhuw kezhuw moved this to Todo in SeamDB Dec 16, 2024
@kezhuw kezhuw moved this from Todo to In Progress in SeamDB Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 Priority Level 0
Projects
Status: In Progress
Development

No branches or pull requests

1 participant