Re: Why not used standart SQL commands?

From: Nicklas Avén <nicklas(dot)aven(at)jordogskog(dot)no>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Why not used standart SQL commands?
Date: 2022-01-10 07:47:02
Message-ID: 34e6a548-8e28-032a-1299-3b233c792102@jordogskog.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Den 2022-01-08 kl. 19:25, skrev Ali Koca:
> Hello,
>
> I'm seeing \dt used for "show tables", \l used for "show databases". Why
> not standart SQL syntax words? Why specified PostgreSQL commands?
> I can't figure out that.
>
> Ali
>
>

The psql backslash commands is just helper commands that wraps the
actual sql. With the -E, --echo-hidden option when starting psql you can
see the real sql.

The \dt command for instance uses this 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 '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
     LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam
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;

/Nicklas Avén

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Torello Querci 2022-01-10 08:02:27 Install pg_dump and pg_restore on UBI8 and UBI8-minimal
Previous Message Thomas Munro 2022-01-09 20:55:02 Re: create database hangs forever on WSL - autovacuum deadlock?