# LogicTest: default parallel-stmts

# Verify pg_catalog database handles mutation statements correctly.

query error database "pg_catalog" does not exist
ALTER DATABASE pg_catalog RENAME TO not_pg_catalog

statement error schema cannot be modified: "pg_catalog"
CREATE TABLE pg_catalog.t (x INT)

query error database "pg_catalog" does not exist
DROP DATABASE pg_catalog

query T
SHOW TABLES FROM pg_catalog
----
pg_am
pg_attrdef
pg_attribute
pg_auth_members
pg_class
pg_collation
pg_constraint
pg_database
pg_depend
pg_description
pg_enum
pg_extension
pg_foreign_data_wrapper
pg_foreign_server
pg_foreign_table
pg_index
pg_indexes
pg_inherits
pg_language
pg_namespace
pg_operator
pg_proc
pg_range
pg_rewrite
pg_roles
pg_sequence
pg_settings
pg_tables
pg_tablespace
pg_trigger
pg_type
pg_user
pg_user_mapping
pg_views

# Verify "pg_catalog" is a regular db name

statement ok
CREATE DATABASE other_db

statement ok
ALTER DATABASE other_db RENAME TO pg_catalog

statement error database "pg_catalog" already exists
CREATE DATABASE pg_catalog

statement ok
DROP DATABASE pg_catalog

# the following query checks that the planDataSource instantiated from
# a virtual table in the FROM clause is properly deallocated even when
# query preparation causes an error. #9853
query error unknown function
SELECT * FROM pg_catalog.pg_class c WHERE nonexistent_function()

# Verify pg_catalog handles reflection correctly.

query T
SHOW TABLES FROM test.pg_catalog
----
pg_am
pg_attrdef
pg_attribute
pg_auth_members
pg_class
pg_collation
pg_constraint
pg_database
pg_depend
pg_description
pg_enum
pg_extension
pg_foreign_data_wrapper
pg_foreign_server
pg_foreign_table
pg_index
pg_indexes
pg_inherits
pg_language
pg_namespace
pg_operator
pg_proc
pg_range
pg_rewrite
pg_roles
pg_sequence
pg_settings
pg_tables
pg_tablespace
pg_trigger
pg_type
pg_user
pg_user_mapping
pg_views

query TT colnames
SHOW CREATE TABLE pg_catalog.pg_namespace
----
Table                    CreateTable
pg_catalog.pg_namespace  CREATE TABLE pg_namespace (
                             oid OID NULL,
                             nspname NAME NOT NULL,
                             nspowner OID NULL,
                             nspacl STRING[] NULL
)

query TTBTT colnames
SHOW COLUMNS FROM pg_catalog.pg_namespace
----
Field     Type      Null   Default Indices
oid       OID       true   NULL    {}
nspname   NAME      false  NULL    {}
nspowner  OID       true   NULL    {}
nspacl    STRING[]  true   NULL    {}

query TTBITTBB colnames
SHOW INDEXES FROM pg_catalog.pg_namespace
----
Table  Name  Unique  Seq  Column  Direction  Storing  Implicit

query TTTTT colnames
SHOW CONSTRAINTS FROM pg_catalog.pg_namespace
----
Table         Name     Type  Column(s)  Details

query TTTTT colnames
SHOW GRANTS ON pg_catalog.pg_namespace
----
Database Schema Table  User  Privileges


# Verify selecting from pg_catalog.

statement ok
CREATE DATABASE constraint_db

statement ok
CREATE TABLE constraint_db.t1 (
  p FLOAT PRIMARY KEY,
  a INT UNIQUE,
  b INT,
  c INT DEFAULT 12,
  UNIQUE INDEX index_key(b, c)
)

statement ok
CREATE TABLE constraint_db.t2 (
    t1_ID INT,
    CONSTRAINT fk FOREIGN KEY (t1_ID) REFERENCES constraint_db.t1(a),
    INDEX (t1_ID)
)

statement ok
CREATE TABLE constraint_db.t3 (
    a INT,
    b INT CHECK (b > 11),
    c STRING DEFAULT 'FOO',
    CONSTRAINT fk FOREIGN KEY (a, b) REFERENCES constraint_db.t1(b, c),
    INDEX (a, b DESC) STORING (c)
)

statement ok
CREATE VIEW constraint_db.v1 AS SELECT p,a,b,c FROM constraint_db.t1

## pg_catalog.pg_namespace

query OTOT colnames
SELECT * FROM pg_catalog.pg_namespace
----
oid         nspname             nspowner  nspacl
2770537123  crdb_internal       NULL      NULL
711679804   information_schema  NULL      NULL
1809486327  pg_catalog          NULL      NULL
1692868363  public              NULL      NULL

## pg_catalog.pg_database

query OTOITTBB colnames
SELECT oid, datname, datdba, encoding, datcollate, datctype, datistemplate, datallowconn
FROM pg_catalog.pg_database
ORDER BY oid
----
oid         datname        datdba  encoding  datcollate  datctype    datistemplate  datallowconn
381876367   system         NULL    6         en_US.utf8  en_US.utf8  false          true
437457361   constraint_db  NULL    6         en_US.utf8  en_US.utf8  false          true
1965331359  test           NULL    6         en_US.utf8  en_US.utf8  false          true

query OTIOIIOT colnames
SELECT oid, datname, datconnlimit, datlastsysoid, datfrozenxid, datminmxid, dattablespace, datacl
FROM pg_catalog.pg_database
ORDER BY oid
----
oid         datname        datconnlimit  datlastsysoid  datfrozenxid  datminmxid  dattablespace  datacl
381876367   system         -1            NULL           NULL          NULL        0              NULL
437457361   constraint_db  -1            NULL           NULL          NULL        0              NULL
1965331359  test           -1            NULL           NULL          NULL        0              NULL

## pg_catalog.pg_tables

statement ok
SET DATABASE = constraint_db

query TTTTBBBB colnames
SELECT * FROM constraint_db.pg_catalog.pg_tables WHERE schemaname = 'public'
----
schemaname  tablename  tableowner  tablespace  hasindexes  hasrules  hastriggers  rowsecurity
public      t1         NULL        NULL        true        false     false        false
public      t2         NULL        NULL        true        false     false        false
public      t3         NULL        NULL        true        false     false        false

query TB colnames
SELECT tablename, hasindexes FROM pg_catalog.pg_tables WHERE schemaname = 'information_schema' AND tablename LIKE '%table%'
----
tablename          hasindexes
role_table_grants  false
table_constraints  false
table_privileges   false
tables             false

## pg_catalog.pg_tablespace

query OTOTT colnames
SELECT oid, spcname, spcowner, spcacl, spcoptions FROM pg_tablespace
----
oid  spcname     spcowner  spcacl  spcoptions
0    pg_default  NULL      NULL    NULL

## pg_catalog.pg_views

query TTTT colnames
SELECT * FROM pg_catalog.pg_views
----
schemaname  viewname  viewowner  definition
public      v1        NULL       SELECT p, a, b, c FROM constraint_db.public.t1

## pg_catalog.pg_class

query OTOOOOOO colnames
SELECT c.oid, relname, relnamespace, reltype, relowner, relam, relfilenode, reltablespace
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
oid         relname       relnamespace  reltype  relowner  relam  relfilenode  reltablespace
1509766457  t1            3969441927    0        NULL      NULL   0            0
3075386613  primary       3969441927    0        NULL      NULL   0            0
3075386614  t1_a_key      3969441927    0        NULL      NULL   0            0
3075386615  index_key     3969441927    0        NULL      NULL   0            0
1275321073  t2            3969441927    0        NULL      NULL   0            0
4026878981  primary       3969441927    0        NULL      NULL   0            0
4026878982  t2_t1_id_idx  3969441927    0        NULL      NULL   0            0
1308729185  t3            3969441927    0        NULL      NULL   0            0
126881509   primary       3969441927    0        NULL      NULL   0            0
126881510   t3_a_b_idx    3969441927    0        NULL      NULL   0            0
1543910075  v1            3969441927    0        NULL      NULL   0            0

query TIRIOBBT colnames
SELECT relname, relpages, reltuples, relallvisible, reltoastrelid, relhasindex, relisshared, relpersistence
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname       relpages  reltuples  relallvisible  reltoastrelid  relhasindex  relisshared  relpersistence
t1            NULL      NULL       0              0              true         false        p
primary       NULL      NULL       0              0              false        false        p
t1_a_key      NULL      NULL       0              0              false        false        p
index_key     NULL      NULL       0              0              false        false        p
t2            NULL      NULL       0              0              true         false        p
primary       NULL      NULL       0              0              false        false        p
t2_t1_id_idx  NULL      NULL       0              0              false        false        p
t3            NULL      NULL       0              0              true         false        p
primary       NULL      NULL       0              0              false        false        p
t3_a_b_idx    NULL      NULL       0              0              false        false        p
v1            NULL      NULL       0              0              false        false        p

query TBTIIBB colnames
SELECT relname, relistemp, relkind, relnatts, relchecks, relhasoids, relhaspkey
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname       relistemp  relkind  relnatts  relchecks  relhasoids  relhaspkey
t1            false      r        4         0          false       true
primary       false      i        1         0          false       false
t1_a_key      false      i        1         0          false       false
index_key     false      i        2         0          false       false
t2            false      r        2         0          false       true
primary       false      i        1         0          false       false
t2_t1_id_idx  false      i        1         0          false       false
t3            false      r        4         1          false       true
primary       false      i        1         0          false       false
t3_a_b_idx    false      i        2         0          false       false
v1            false      v        4         0          false       false

query TBBBITT colnames
SELECT relname, relhasrules, relhastriggers, relhassubclass, relfrozenxid, relacl, reloptions
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname       relhasrules  relhastriggers  relhassubclass  relfrozenxid  relacl  reloptions
t1            false        false           false           0             NULL    NULL
primary       false        false           false           0             NULL    NULL
t1_a_key      false        false           false           0             NULL    NULL
index_key     false        false           false           0             NULL    NULL
t2            false        false           false           0             NULL    NULL
primary       false        false           false           0             NULL    NULL
t2_t1_id_idx  false        false           false           0             NULL    NULL
t3            false        false           false           0             NULL    NULL
primary       false        false           false           0             NULL    NULL
t3_a_b_idx    false        false           false           0             NULL    NULL
v1            false        false           false           0             NULL    NULL

## pg_catalog.pg_attribute

query OTTOIIIII colnames
SELECT attrelid, c.relname, attname, atttypid, attstattarget, attlen, attnum, attndims, attcacheoff
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
attrelid    relname       attname  atttypid  attstattarget  attlen  attnum  attndims  attcacheoff
1509766457  t1            p        701       0              8       1       0         -1
1509766457  t1            a        20        0              8       2       0         -1
1509766457  t1            b        20        0              8       3       0         -1
1509766457  t1            c        20        0              8       4       0         -1
3075386613  primary       p        701       0              8       1       0         -1
3075386614  t1_a_key      a        20        0              8       1       0         -1
3075386615  index_key     b        20        0              8       1       0         -1
3075386615  index_key     c        20        0              8       2       0         -1
1275321073  t2            t1_id    20        0              8       1       0         -1
4026878982  t2_t1_id_idx  t1_id    20        0              8       1       0         -1
1308729185  t3            a        20        0              8       1       0         -1
1308729185  t3            b        20        0              8       2       0         -1
1308729185  t3            c        25        0              -1      3       0         -1
126881510   t3_a_b_idx    a        20        0              8       1       0         -1
126881510   t3_a_b_idx    b        20        0              8       2       0         -1
1543910075  v1            p        701       0              8       1       0         -1
1543910075  v1            a        20        0              8       2       0         -1
1543910075  v1            b        20        0              8       3       0         -1
1543910075  v1            c        20        0              8       4       0         -1

query TTIBTTBB colnames
SELECT c.relname, attname, atttypmod, attbyval, attstorage, attalign, attnotnull, atthasdef
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname       attname  atttypmod  attbyval  attstorage  attalign  attnotnull  atthasdef
t1            p        -1         NULL      NULL        NULL      true        false
t1            a        -1         NULL      NULL        NULL      false       false
t1            b        -1         NULL      NULL        NULL      false       false
t1            c        -1         NULL      NULL        NULL      false       true
primary       p        -1         NULL      NULL        NULL      true        false
t1_a_key      a        -1         NULL      NULL        NULL      false       false
index_key     b        -1         NULL      NULL        NULL      false       false
index_key     c        -1         NULL      NULL        NULL      false       true
t2            t1_id    -1         NULL      NULL        NULL      false       false
t2_t1_id_idx  t1_id    -1         NULL      NULL        NULL      false       false
t3            a        -1         NULL      NULL        NULL      false       false
t3            b        -1         NULL      NULL        NULL      false       false
t3            c        -1         NULL      NULL        NULL      false       true
t3_a_b_idx    a        -1         NULL      NULL        NULL      false       false
t3_a_b_idx    b        -1         NULL      NULL        NULL      false       false
v1            p        -1         NULL      NULL        NULL      true        false
v1            a        -1         NULL      NULL        NULL      true        false
v1            b        -1         NULL      NULL        NULL      true        false
v1            c        -1         NULL      NULL        NULL      true        false

query TTBBITTT colnames
SELECT c.relname, attname, attisdropped, attislocal, attinhcount, attacl, attoptions, attfdwoptions
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname       attname  attisdropped  attislocal  attinhcount  attacl  attoptions  attfdwoptions
t1            p        false         true        0            NULL    NULL        NULL
t1            a        false         true        0            NULL    NULL        NULL
t1            b        false         true        0            NULL    NULL        NULL
t1            c        false         true        0            NULL    NULL        NULL
primary       p        false         true        0            NULL    NULL        NULL
t1_a_key      a        false         true        0            NULL    NULL        NULL
index_key     b        false         true        0            NULL    NULL        NULL
index_key     c        false         true        0            NULL    NULL        NULL
t2            t1_id    false         true        0            NULL    NULL        NULL
t2_t1_id_idx  t1_id    false         true        0            NULL    NULL        NULL
t3            a        false         true        0            NULL    NULL        NULL
t3            b        false         true        0            NULL    NULL        NULL
t3            c        false         true        0            NULL    NULL        NULL
t3_a_b_idx    a        false         true        0            NULL    NULL        NULL
t3_a_b_idx    b        false         true        0            NULL    NULL        NULL
v1            p        false         true        0            NULL    NULL        NULL
v1            a        false         true        0            NULL    NULL        NULL
v1            b        false         true        0            NULL    NULL        NULL
v1            c        false         true        0            NULL    NULL        NULL

# Check relkind codes.
statement ok
CREATE DATABASE relkinds

statement ok
SET DATABASE = relkinds

statement ok
CREATE TABLE tbl_test (k int primary key, v int)

statement ok
CREATE INDEX tbl_test_v_idx ON tbl_test (v)

statement ok
CREATE VIEW view_test AS SELECT k, v FROM tbl_test ORDER BY v

statement ok
CREATE SEQUENCE seq_test

query TT
SELECT relname, relkind
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
ORDER BY relname
----
primary         i
seq_test        S
tbl_test        r
tbl_test_v_idx  i
view_test       v

statement ok
DROP DATABASE relkinds

statement ok
SET DATABASE = constraint_db

# Select all columns with collations.
query TTTOT colnames
SELECT c.relname, attname, t.typname, attcollation, k.collname
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
JOIN pg_catalog.pg_type t ON a.atttypid = t.oid
JOIN pg_catalog.pg_collation k ON a.attcollation = k.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
relname  attname  typname  attcollation  collname
t3       c        text     1661428263    en-US


## pg_catalog.pg_am

query OTOT colnames
SELECT *
FROM pg_catalog.pg_am
----
oid         amname  amhandler  amtype
2631952481  prefix  NULL       i

## pg_catalog.pg_attrdef

query OTOITT colnames
SELECT ad.oid, c.relname, adrelid, adnum, adbin, adsrc
FROM pg_catalog.pg_attrdef ad
JOIN pg_catalog.pg_class c ON ad.adrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
oid         relname  adrelid     adnum  adbin           adsrc
2546105486  t1       1509766457  4      12:::INT        12:::INT
2449897171  t3       1308729185  3      'FOO':::STRING  'FOO':::STRING

## pg_catalog.pg_indexes

query OTTTT colnames
SELECT crdb_oid, schemaname, tablename, indexname, tablespace
FROM pg_catalog.pg_indexes
WHERE schemaname = 'public'
----
crdb_oid    schemaname  tablename  indexname     tablespace
3075386613  public      t1         primary       NULL
3075386614  public      t1         t1_a_key      NULL
3075386615  public      t1         index_key     NULL
4026878981  public      t2         primary       NULL
4026878982  public      t2         t2_t1_id_idx  NULL
126881509   public      t3         primary       NULL
126881510   public      t3         t3_a_b_idx    NULL

query OTTT colnames
SELECT crdb_oid, tablename, indexname, indexdef
FROM pg_catalog.pg_indexes
WHERE schemaname = 'public'
----
crdb_oid    tablename  indexname     indexdef
3075386613  t1         primary       CREATE UNIQUE INDEX "primary" ON constraint_db.public.t1 (p ASC)
3075386614  t1         t1_a_key      CREATE UNIQUE INDEX t1_a_key ON constraint_db.public.t1 (a ASC)
3075386615  t1         index_key     CREATE UNIQUE INDEX index_key ON constraint_db.public.t1 (b ASC, c ASC)
4026878981  t2         primary       CREATE UNIQUE INDEX "primary" ON constraint_db.public.t2 (rowid ASC)
4026878982  t2         t2_t1_id_idx  CREATE INDEX t2_t1_id_idx ON constraint_db.public.t2 (t1_id ASC)
126881509   t3         primary       CREATE UNIQUE INDEX "primary" ON constraint_db.public.t3 (rowid ASC)
126881510   t3         t3_a_b_idx    CREATE INDEX t3_a_b_idx ON constraint_db.public.t3 (a ASC, b DESC) STORING (c)

## pg_catalog.pg_index

query OOIBBB colnames
SELECT indexrelid, indrelid, indnatts, indisunique, indisprimary, indisexclusion
from pg_catalog.pg_index
WHERE indnatts = 2
----
indexrelid  indrelid    indnatts  indisunique  indisprimary  indisexclusion
3075386615  1509766457  2         true         false         false
126881510   1308729185  2         false        false         false

query OBBBBB colnames
SELECT indexrelid, indimmediate, indisclustered, indisvalid, indcheckxmin, indisready
from pg_catalog.pg_index
WHERE indnatts = 2
----
indexrelid  indimmediate  indisclustered  indisvalid  indcheckxmin  indisready
3075386615  true          false           true        false         false
126881510   false         false           true        false         false

query OOBBTIIITT colnames
SELECT indexrelid, indrelid, indislive, indisreplident, indkey, indcollation, indclass, indoption, indexprs, indpred
from pg_catalog.pg_index
WHERE indnatts = 2
----
indexrelid  indrelid    indislive  indisreplident  indkey  indcollation  indclass  indoption  indexprs  indpred
3075386615  1509766457  true       false           3 4     0             0         0          NULL      NULL
126881510   1308729185  true       false           1 2     0             0         0          NULL      NULL

## pg_catalog.pg_collation

query OTOOITT colnames
SELECT * FROM pg_collation
WHERE collname='en-US'
----
oid         collname  collnamespace  collowner  collencoding  collcollate  collctype
1661428263  en-US     3969441927     NULL       6             NULL         NULL

## pg_catalog.pg_constraint
##
## These order of this virtual table is non-deterministic, so all queries must
## explicitly add an ORDER BY clause.

query OTOT colnames
SELECT con.oid, conname, connamespace, contype
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'
ORDER BY con.oid
----
oid         conname    connamespace  contype
302390735   check_b    3969441927    c
378079884   index_key  3969441927    u
378079885   t1_a_key   3969441927    u
2517385387  fk         3969441927    f
2704194502  fk         3969441927    f
3077848825  primary    3969441927    p

query TTBBBOOO colnames
SELECT conname, contype, condeferrable, condeferred, convalidated, conrelid, contypid, conindid
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'
ORDER BY con.oid
----
conname    contype  condeferrable  condeferred  convalidated  conrelid    contypid  conindid
check_b    c        false          false        true          1308729185  0         0
index_key  u        false          false        true          1509766457  0         3075386615
t1_a_key   u        false          false        true          1509766457  0         3075386614
fk         f        false          false        true          1275321073  0         3075386614
fk         f        false          false        true          1308729185  0         3075386615
primary    p        false          false        true          1509766457  0         3075386613

query T
SELECT conname
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype NOT IN ('c', 'f', 'p', 'u')
ORDER BY con.oid
----

query TOTTT colnames
SELECT conname, confrelid, confupdtype, confdeltype, confmatchtype
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u')
ORDER BY con.oid
----
conname    confrelid  confupdtype  confdeltype  confmatchtype
check_b    0          NULL         NULL         NULL
index_key  0          NULL         NULL         NULL
t1_a_key   0          NULL         NULL         NULL
primary    0          NULL         NULL         NULL

query TOTTT colnames
SELECT conname, confrelid, confupdtype, confdeltype, confmatchtype
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype = 'f'
ORDER BY con.oid
----
conname  confrelid   confupdtype  confdeltype  confmatchtype
fk       1509766457  a            a            s
fk       1509766457  a            a            s

query TBIBT colnames
SELECT conname, conislocal, coninhcount, connoinherit, conkey
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'
ORDER BY con.oid
----
conname    conislocal  coninhcount  connoinherit  conkey
check_b    true        0            true          {2}
index_key  true        0            true          {3,4}
t1_a_key   true        0            true          {2}
fk         true        0            true          {1}
fk         true        0            true          {1,2}
primary    true        0            true          {1}

query TTTTTTTT colnames
SELECT conname, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin, consrc
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype IN ('c', 'p', 'u')
ORDER BY con.oid
----
conname    confkey  conpfeqop  conppeqop  conffeqop  conexclop  conbin  consrc
check_b    NULL     NULL       NULL       NULL       NULL       b > 11  b > 11
index_key  NULL     NULL       NULL       NULL       NULL       NULL    NULL
t1_a_key   NULL     NULL       NULL       NULL       NULL       NULL    NULL
primary    NULL     NULL       NULL       NULL       NULL       NULL    NULL

query TTTTTTTT colnames
SELECT conname, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin, consrc
FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public' AND contype = 'f'
ORDER BY con.oid
----
conname  confkey  conpfeqop  conppeqop  conffeqop  conexclop  conbin  consrc
fk       {2}      NULL       NULL       NULL       NULL       NULL    NULL
fk       {3,4}    NULL       NULL       NULL       NULL       NULL    NULL

## pg_catalog.pg_depend

query OOIOOIT colnames
SELECT classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype
FROM pg_catalog.pg_depend
ORDER BY objid
----
classid     objid       objsubid  refclassid  refobjid    refobjsubid  deptype
1539915808  2517385387  0         2523326295  3075386614  0            n
1539915808  2704194502  0         2523326295  3075386615  0            n

# All entries in pg_depend are dependency links from the pg_constraint system
# table to the pg_class system table.

query OOTT colnames
SELECT DISTINCT classid, refclassid, cla.relname AS tablename, refcla.relname AS reftablename
FROM pg_catalog.pg_depend
JOIN pg_class cla ON classid=cla.oid
JOIN pg_class refcla ON refclassid=refcla.oid
----
classid     refclassid  tablename      reftablename
1539915808  2523326295  pg_constraint  pg_class

# All entries in pg_depend are foreign key constraints that reference an index
# in pg_class.

query TT colnames
SELECT relname, relkind
FROM pg_depend
JOIN pg_class ON refobjid=pg_class.oid
ORDER BY relname
----
relname    relkind
index_key  i
t1_a_key   i


# All entries are pg_depend are linked to a foreign key constraint whose
# supporting index is the referenced object id.

query T colnames
SELECT DISTINCT pg_constraint.contype
FROM pg_depend
JOIN pg_constraint ON objid=pg_constraint.oid AND refobjid=pg_constraint.conindid
----
contype
f

## pg_catalog.pg_type

query OTOOIBT colnames
SELECT oid, typname, typnamespace, typowner, typlen, typbyval, typtype
FROM pg_catalog.pg_type
ORDER BY oid
----
oid   typname       typnamespace  typowner  typlen  typbyval  typtype
16    bool          3572887043    NULL      1       true      b
17    bytea         3572887043    NULL      -1      false     b
19    name          3572887043    NULL      -1      false     b
20    int8          3572887043    NULL      8       true      b
21    int2          3572887043    NULL      8       true      b
22    int2vector    3572887043    NULL      -1      false     b
23    int4          3572887043    NULL      8       true      b
24    regproc       3572887043    NULL      8       true      b
25    text          3572887043    NULL      -1      false     b
26    oid           3572887043    NULL      8       true      b
30    oidvector     3572887043    NULL      -1      false     b
700   float4        3572887043    NULL      8       true      b
701   float8        3572887043    NULL      8       true      b
869   inet          3572887043    NULL      24      true      b
1000  _bool         3572887043    NULL      -1      false     b
1001  _bytea        3572887043    NULL      -1      false     b
1003  _name         3572887043    NULL      -1      false     b
1005  _int2         3572887043    NULL      -1      false     b
1007  _int4         3572887043    NULL      -1      false     b
1009  _text         3572887043    NULL      -1      false     b
1015  _varchar      3572887043    NULL      -1      false     b
1016  _int8         3572887043    NULL      -1      false     b
1021  _float4       3572887043    NULL      -1      false     b
1022  _float8       3572887043    NULL      -1      false     b
1028  _oid          3572887043    NULL      -1      false     b
1041  _inet         3572887043    NULL      -1      false     b
1043  varchar       3572887043    NULL      -1      false     b
1082  date          3572887043    NULL      8       true      b
1083  time          3572887043    NULL      8       true      b
1114  timestamp     3572887043    NULL      24      true      b
1115  _timestamp    3572887043    NULL      -1      false     b
1182  _date         3572887043    NULL      -1      false     b
1183  _time         3572887043    NULL      -1      false     b
1184  timestamptz   3572887043    NULL      24      true      b
1185  _timestamptz  3572887043    NULL      -1      false     b
1186  interval      3572887043    NULL      24      true      b
1187  _interval     3572887043    NULL      -1      false     b
1231  _numeric      3572887043    NULL      -1      false     b
1700  numeric       3572887043    NULL      -1      false     b
2202  regprocedure  3572887043    NULL      8       true      b
2205  regclass      3572887043    NULL      8       true      b
2206  regtype       3572887043    NULL      8       true      b
2249  record        3572887043    NULL      0       true      b
2277  anyarray      3572887043    NULL      -1      false     b
2283  anyelement    3572887043    NULL      -1      false     b
2950  uuid          3572887043    NULL      16      true      b
2951  _uuid         3572887043    NULL      -1      false     b
3802  jsonb         3572887043    NULL      -1      false     b
4089  regnamespace  3572887043    NULL      8       true      b

query OTTBBTOOO colnames
SELECT oid, typname, typcategory, typispreferred, typisdefined, typdelim, typrelid, typelem, typarray
FROM pg_catalog.pg_type
ORDER BY oid
----
oid   typname       typcategory  typispreferred  typisdefined  typdelim  typrelid  typelem  typarray
16    bool          B            false           true          ,         0         0        1000
17    bytea         U            false           true          ,         0         0        1001
19    name          S            false           true          ,         0         0        1003
20    int8          N            false           true          ,         0         0        1016
21    int2          N            false           true          ,         0         0        1005
22    int2vector    A            false           true          ,         0         21       0
23    int4          N            false           true          ,         0         0        1007
24    regproc       N            false           true          ,         0         0        0
25    text          S            false           true          ,         0         0        1009
26    oid           N            false           true          ,         0         0        1028
30    oidvector     A            false           true          ,         0         26       0
700   float4        N            false           true          ,         0         0        1021
701   float8        N            false           true          ,         0         0        1022
869   inet          I            false           true          ,         0         0        1041
1000  _bool         A            false           true          ,         0         16       0
1001  _bytea        A            false           true          ,         0         17       0
1003  _name         A            false           true          ,         0         19       0
1005  _int2         A            false           true          ,         0         21       0
1007  _int4         A            false           true          ,         0         23       0
1009  _text         A            false           true          ,         0         25       0
1015  _varchar      A            false           true          ,         0         1043     0
1016  _int8         A            false           true          ,         0         20       0
1021  _float4       A            false           true          ,         0         700      0
1022  _float8       A            false           true          ,         0         701      0
1028  _oid          A            false           true          ,         0         26       0
1041  _inet         A            false           true          ,         0         869      0
1043  varchar       S            false           true          ,         0         0        1015
1082  date          D            false           true          ,         0         0        1182
1083  time          D            false           true          ,         0         0        1183
1114  timestamp     D            false           true          ,         0         0        1115
1115  _timestamp    A            false           true          ,         0         1114     0
1182  _date         A            false           true          ,         0         1082     0
1183  _time         A            false           true          ,         0         1083     0
1184  timestamptz   D            false           true          ,         0         0        1185
1185  _timestamptz  A            false           true          ,         0         1184     0
1186  interval      T            false           true          ,         0         0        1187
1187  _interval     A            false           true          ,         0         1186     0
1231  _numeric      A            false           true          ,         0         1700     0
1700  numeric       N            false           true          ,         0         0        1231
2202  regprocedure  N            false           true          ,         0         0        0
2205  regclass      N            false           true          ,         0         0        0
2206  regtype       N            false           true          ,         0         0        0
2249  record        P            false           true          ,         0         0        0
2277  anyarray      A            false           true          ,         0         2283     0
2283  anyelement    P            false           true          ,         0         0        2277
2950  uuid          U            false           true          ,         0         0        2951
2951  _uuid         A            false           true          ,         0         2950     0
3802  jsonb         U            false           true          ,         0         0        0
4089  regnamespace  N            false           true          ,         0         0        0

query OTOOOOOOO colnames
SELECT oid, typname, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze
FROM pg_catalog.pg_type
ORDER BY oid
----
oid   typname       typinput        typoutput        typreceive        typsend           typmodin  typmodout  typanalyze
16    bool          boolin          boolout          boolrecv          boolsend          0         0          0
17    bytea         byteain         byteaout         bytearecv         byteasend         0         0          0
19    name          namein          nameout          namerecv          namesend          0         0          0
20    int8          int8in          int8out          int8recv          int8send          0         0          0
21    int2          int2in          int2out          int2recv          int2send          0         0          0
22    int2vector    int2vectorin    int2vectorout    int2vectorrecv    int2vectorsend    0         0          0
23    int4          int4in          int4out          int4recv          int4send          0         0          0
24    regproc       regprocin       regprocout       regprocrecv       regprocsend       0         0          0
25    text          textin          textout          textrecv          textsend          0         0          0
26    oid           oidin           oidout           oidrecv           oidsend           0         0          0
30    oidvector     oidvectorin     oidvectorout     oidvectorrecv     oidvectorsend     0         0          0
700   float4        float4in        float4out        float4recv        float4send        0         0          0
701   float8        float8in        float8out        float8recv        float8send        0         0          0
869   inet          inetin          inetout          inetrecv          inetsend          0         0          0
1000  _bool         array_in        array_out        array_recv        array_send        0         0          0
1001  _bytea        array_in        array_out        array_recv        array_send        0         0          0
1003  _name         array_in        array_out        array_recv        array_send        0         0          0
1005  _int2         array_in        array_out        array_recv        array_send        0         0          0
1007  _int4         array_in        array_out        array_recv        array_send        0         0          0
1009  _text         array_in        array_out        array_recv        array_send        0         0          0
1015  _varchar      array_in        array_out        array_recv        array_send        0         0          0
1016  _int8         array_in        array_out        array_recv        array_send        0         0          0
1021  _float4       array_in        array_out        array_recv        array_send        0         0          0
1022  _float8       array_in        array_out        array_recv        array_send        0         0          0
1028  _oid          array_in        array_out        array_recv        array_send        0         0          0
1041  _inet         array_in        array_out        array_recv        array_send        0         0          0
1043  varchar       varcharin       varcharout       varcharrecv       varcharsend       0         0          0
1082  date          date_in         date_out         date_recv         date_send         0         0          0
1083  time          time_in         time_out         time_recv         time_send         0         0          0
1114  timestamp     timestamp_in    timestamp_out    timestamp_recv    timestamp_send    0         0          0
1115  _timestamp    array_in        array_out        array_recv        array_send        0         0          0
1182  _date         array_in        array_out        array_recv        array_send        0         0          0
1183  _time         array_in        array_out        array_recv        array_send        0         0          0
1184  timestamptz   timestamptz_in  timestamptz_out  timestamptz_recv  timestamptz_send  0         0          0
1185  _timestamptz  array_in        array_out        array_recv        array_send        0         0          0
1186  interval      interval_in     interval_out     interval_recv     interval_send     0         0          0
1187  _interval     array_in        array_out        array_recv        array_send        0         0          0
1231  _numeric      array_in        array_out        array_recv        array_send        0         0          0
1700  numeric       numeric_in      numeric_out      numeric_recv      numeric_send      0         0          0
2202  regprocedure  regprocedurein  regprocedureout  regprocedurerecv  regproceduresend  0         0          0
2205  regclass      regclassin      regclassout      regclassrecv      regclasssend      0         0          0
2206  regtype       regtypein       regtypeout       regtyperecv       regtypesend       0         0          0
2249  record        record_in       record_out       record_recv       record_send       0         0          0
2277  anyarray      array_in        array_out        array_recv        array_send        0         0          0
2283  anyelement    anyelement_in   anyelement_out   anyelement_recv   anyelement_send   0         0          0
2950  uuid          uuid_in         uuid_out         uuid_recv         uuid_send         0         0          0
2951  _uuid         array_in        array_out        array_recv        array_send        0         0          0
3802  jsonb         jsonb_in        jsonb_out        jsonb_recv        jsonb_send        0         0          0
4089  regnamespace  regnamespacein  regnamespaceout  regnamespacerecv  regnamespacesend  0         0          0

query OTTTBOI colnames
SELECT oid, typname, typalign, typstorage, typnotnull, typbasetype, typtypmod
FROM pg_catalog.pg_type
ORDER BY oid
----
oid   typname       typalign  typstorage  typnotnull  typbasetype  typtypmod
16    bool          NULL      NULL        false       0            -1
17    bytea         NULL      NULL        false       0            -1
19    name          NULL      NULL        false       0            -1
20    int8          NULL      NULL        false       0            -1
21    int2          NULL      NULL        false       0            -1
22    int2vector    NULL      NULL        false       0            -1
23    int4          NULL      NULL        false       0            -1
24    regproc       NULL      NULL        false       0            -1
25    text          NULL      NULL        false       0            -1
26    oid           NULL      NULL        false       0            -1
30    oidvector     NULL      NULL        false       0            -1
700   float4        NULL      NULL        false       0            -1
701   float8        NULL      NULL        false       0            -1
869   inet          NULL      NULL        false       0            -1
1000  _bool         NULL      NULL        false       0            -1
1001  _bytea        NULL      NULL        false       0            -1
1003  _name         NULL      NULL        false       0            -1
1005  _int2         NULL      NULL        false       0            -1
1007  _int4         NULL      NULL        false       0            -1
1009  _text         NULL      NULL        false       0            -1
1015  _varchar      NULL      NULL        false       0            -1
1016  _int8         NULL      NULL        false       0            -1
1021  _float4       NULL      NULL        false       0            -1
1022  _float8       NULL      NULL        false       0            -1
1028  _oid          NULL      NULL        false       0            -1
1041  _inet         NULL      NULL        false       0            -1
1043  varchar       NULL      NULL        false       0            -1
1082  date          NULL      NULL        false       0            -1
1083  time          NULL      NULL        false       0            -1
1114  timestamp     NULL      NULL        false       0            -1
1115  _timestamp    NULL      NULL        false       0            -1
1182  _date         NULL      NULL        false       0            -1
1183  _time         NULL      NULL        false       0            -1
1184  timestamptz   NULL      NULL        false       0            -1
1185  _timestamptz  NULL      NULL        false       0            -1
1186  interval      NULL      NULL        false       0            -1
1187  _interval     NULL      NULL        false       0            -1
1231  _numeric      NULL      NULL        false       0            -1
1700  numeric       NULL      NULL        false       0            -1
2202  regprocedure  NULL      NULL        false       0            -1
2205  regclass      NULL      NULL        false       0            -1
2206  regtype       NULL      NULL        false       0            -1
2249  record        NULL      NULL        false       0            -1
2277  anyarray      NULL      NULL        false       0            -1
2283  anyelement    NULL      NULL        false       0            -1
2950  uuid          NULL      NULL        false       0            -1
2951  _uuid         NULL      NULL        false       0            -1
3802  jsonb         NULL      NULL        false       0            -1
4089  regnamespace  NULL      NULL        false       0            -1

query OTIOTTT colnames
SELECT oid, typname, typndims, typcollation, typdefaultbin, typdefault, typacl
FROM pg_catalog.pg_type
ORDER BY oid
----
oid   typname       typndims  typcollation  typdefaultbin  typdefault  typacl
16    bool          0         0             NULL           NULL        NULL
17    bytea         0         0             NULL           NULL        NULL
19    name          0         1661428263    NULL           NULL        NULL
20    int8          0         0             NULL           NULL        NULL
21    int2          0         0             NULL           NULL        NULL
22    int2vector    0         0             NULL           NULL        NULL
23    int4          0         0             NULL           NULL        NULL
24    regproc       0         0             NULL           NULL        NULL
25    text          0         1661428263    NULL           NULL        NULL
26    oid           0         0             NULL           NULL        NULL
30    oidvector     0         0             NULL           NULL        NULL
700   float4        0         0             NULL           NULL        NULL
701   float8        0         0             NULL           NULL        NULL
869   inet          0         0             NULL           NULL        NULL
1000  _bool         0         0             NULL           NULL        NULL
1001  _bytea        0         0             NULL           NULL        NULL
1003  _name         0         1661428263    NULL           NULL        NULL
1005  _int2         0         0             NULL           NULL        NULL
1007  _int4         0         0             NULL           NULL        NULL
1009  _text         0         1661428263    NULL           NULL        NULL
1015  _varchar      0         1661428263    NULL           NULL        NULL
1016  _int8         0         0             NULL           NULL        NULL
1021  _float4       0         0             NULL           NULL        NULL
1022  _float8       0         0             NULL           NULL        NULL
1028  _oid          0         0             NULL           NULL        NULL
1041  _inet         0         0             NULL           NULL        NULL
1043  varchar       0         1661428263    NULL           NULL        NULL
1082  date          0         0             NULL           NULL        NULL
1083  time          0         0             NULL           NULL        NULL
1114  timestamp     0         0             NULL           NULL        NULL
1115  _timestamp    0         0             NULL           NULL        NULL
1182  _date         0         0             NULL           NULL        NULL
1183  _time         0         0             NULL           NULL        NULL
1184  timestamptz   0         0             NULL           NULL        NULL
1185  _timestamptz  0         0             NULL           NULL        NULL
1186  interval      0         0             NULL           NULL        NULL
1187  _interval     0         0             NULL           NULL        NULL
1231  _numeric      0         0             NULL           NULL        NULL
1700  numeric       0         0             NULL           NULL        NULL
2202  regprocedure  0         0             NULL           NULL        NULL
2205  regclass      0         0             NULL           NULL        NULL
2206  regtype       0         0             NULL           NULL        NULL
2249  record        0         0             NULL           NULL        NULL
2277  anyarray      0         1661428263    NULL           NULL        NULL
2283  anyelement    0         0             NULL           NULL        NULL
2950  uuid          0         0             NULL           NULL        NULL
2951  _uuid         0         0             NULL           NULL        NULL
3802  jsonb         0         0             NULL           NULL        NULL
4089  regnamespace  0         0             NULL           NULL        NULL

## pg_catalog.pg_proc

query TOOOTTO colnames
SELECT proname, pronamespace, proowner, prolang, procost, prorows, provariadic
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    pronamespace  proowner  prolang  procost  prorows  provariadic
substring  3572887043    NULL      0        NULL     NULL     0
substring  3572887043    NULL      0        NULL     NULL     0
substring  3572887043    NULL      0        NULL     NULL     0
substring  3572887043    NULL      0        NULL     NULL     0

query TTBBBB colnames
SELECT proname, protransform, proisagg, proiswindow, prosecdef, proleakproof
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    protransform  proisagg  proiswindow  prosecdef  proleakproof
substring  NULL          false     false        false      true
substring  NULL          false     false        false      true
substring  NULL          false     false        false      true
substring  NULL          false     false        false      true

query TBBTT colnames
SELECT proname, proisstrict, proretset, provolatile, proparallel
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    proisstrict  proretset  provolatile  proparallel
substring  false        false      NULL         NULL
substring  false        false      NULL         NULL
substring  false        false      NULL         NULL
substring  false        false      NULL         NULL

query TIIOTTTT colnames
SELECT proname, pronargs, pronargdefaults, prorettype, proargtypes, proallargtypes, proargmodes, proargdefaults
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    pronargs  pronargdefaults  prorettype  proargtypes  proallargtypes  proargmodes  proargdefaults
substring  2         0                25          25 20        NULL            NULL         NULL
substring  3         0                25          25 20 20     NULL            NULL         NULL
substring  2         0                25          25 25        NULL            NULL         NULL
substring  3         0                25          25 25 25     NULL            NULL         NULL

query TTTTTT colnames
SELECT proname, protrftypes, prosrc, probin, proconfig, proacl
FROM pg_catalog.pg_proc
WHERE proname='substring'
----
proname    protrftypes  prosrc     probin  proconfig  proacl
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL
substring  NULL         substring  NULL    NULL       NULL

query TOIOTT colnames
SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes
FROM pg_catalog.pg_proc
WHERE proname='least'
----
proname  provariadic  pronargs  prorettype  proargtypes  proargmodes
least    2283         1         2283        2283         {"v"}

query TOIOTT colnames
SELECT proname, provariadic, pronargs, prorettype, proargtypes, proargmodes
FROM pg_catalog.pg_proc
WHERE proname='json_extract_path'
----
proname            provariadic  pronargs  prorettype  proargtypes  proargmodes
json_extract_path  25           2         3802        3802 25      {"i","v"}

## pg_catalog.pg_range
query IIIIII colnames
SELECT * from pg_catalog.pg_range
----
rngtypid  rngsubtype  rngcollation  rngsubopc  rngcanonical  rngsubdiff

## pg_catalog.pg_roles

query OTBBBBBBB colnames
SELECT oid, rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcatupdate, rolcanlogin, rolreplication
FROM pg_catalog.pg_roles
ORDER BY rolname
----
oid         rolname   rolsuper  rolinherit  rolcreaterole  rolcreatedb  rolcatupdate  rolcanlogin  rolreplication
823966177   admin     true      true        true           true         false         false        false
2901009604  root      true      false       true           true         false         true         false
2499926009  testuser  false     false       false          false        false         true         false

query OTITTBT colnames
SELECT oid, rolname, rolconnlimit, rolpassword, rolvaliduntil, rolbypassrls, rolconfig
FROM pg_catalog.pg_roles
ORDER BY rolname
----
oid         rolname   rolconnlimit  rolpassword  rolvaliduntil  rolbypassrls  rolconfig
823966177   admin     -1            ********     NULL           false         NULL
2901009604  root      -1            ********     NULL           false         NULL
2499926009  testuser  -1            ********     NULL           false         NULL

## pg_catalog.pg_auth_members

query OOOB colnames
SELECT roleid, member, grantor, admin_option
FROM pg_catalog.pg_auth_members
----
roleid     member      grantor  admin_option
823966177  2901009604  NULL     true

## pg_catalog.pg_user

query TOBBBBTTA colnames
SELECT usename, usesysid, usecreatedb, usesuper, userepl, usebypassrls, passwd, valuntil, useconfig
FROM pg_catalog.pg_user
ORDER BY usename
----
usename   usesysid    usecreatedb  usesuper  userepl  usebypassrls  passwd    valuntil  useconfig
root      2901009604  true         true      false    false         ********  NULL      NULL
testuser  2499926009  false        false     false    false         ********  NULL      NULL

## pg_catalog.pg_description

query OOIT colnames
SELECT objoid, classoid, objsubid, description FROM pg_catalog.pg_description
----
objoid  classoid  objsubid  description

## pg_catalog.pg_enum

query OORT colnames
SELECT * FROM pg_catalog.pg_enum
----
oid  enumtypid  enumsortorder  enumlabel

## pg_catalog.pg_extension
query TOOBTTT colnames
SELECT * FROM pg_catalog.pg_extension
----
extname  extowner  extnamespace  extrelocatable  extversion  extconfig  extcondition

## pg_catalog.pg_settings

statement ok
SET DATABASE = test

query TTTTTT colnames
SELECT name, setting, category, short_desc, extra_desc, vartype FROM pg_catalog.pg_settings
----
name                            setting       category  short_desc  extra_desc  vartype
application_name                ·             NULL      NULL        NULL        string
client_encoding                 UTF8          NULL      NULL        NULL        string
client_min_messages             ·             NULL      NULL        NULL        string
database                        test          NULL      NULL        NULL        string
datestyle                       ISO           NULL      NULL        NULL        string
default_transaction_isolation   serializable  NULL      NULL        NULL        string
default_transaction_read_only   off           NULL      NULL        NULL        string
distsql                         off           NULL      NULL        NULL        string
experimental_force_lookup_join  off           NULL      NULL        NULL        string
experimental_opt                off           NULL      NULL        NULL        string
extra_float_digits              ·             NULL      NULL        NULL        string
intervalstyle                   postgres      NULL      NULL        NULL        string
max_index_keys                  32            NULL      NULL        NULL        string
node_id                         1             NULL      NULL        NULL        string
search_path                     public        NULL      NULL        NULL        string
server_version                  9.5.0         NULL      NULL        NULL        string
server_version_num              90500         NULL      NULL        NULL        string
session_user                    root          NULL      NULL        NULL        string
sql_safe_updates                false         NULL      NULL        NULL        string
standard_conforming_strings     on            NULL      NULL        NULL        string
timezone                        UTC           NULL      NULL        NULL        string
tracing                         off           NULL      NULL        NULL        string
transaction_isolation           serializable  NULL      NULL        NULL        string
transaction_priority            normal        NULL      NULL        NULL        string
transaction_read_only           off           NULL      NULL        NULL        string
transaction_status              NoTxn         NULL      NULL        NULL        string

query TTTTTTT colnames
SELECT name, setting, unit, context, enumvals, boot_val, reset_val FROM pg_catalog.pg_settings
----
name                            setting       unit  context  enumvals  boot_val      reset_val
application_name                ·             NULL  user     NULL      ·             ·
client_encoding                 UTF8          NULL  user     NULL      UTF8          UTF8
client_min_messages             ·             NULL  user     NULL      ·             ·
database                        test          NULL  user     NULL      test          test
datestyle                       ISO           NULL  user     NULL      ISO           ISO
default_transaction_isolation   serializable  NULL  user     NULL      serializable  serializable
default_transaction_read_only   off           NULL  user     NULL      off           off
distsql                         off           NULL  user     NULL      off           off
experimental_force_lookup_join  off           NULL  user     NULL      off           off
experimental_opt                off           NULL  user     NULL      off           off
extra_float_digits              ·             NULL  user     NULL      ·             ·
intervalstyle                   postgres      NULL  user     NULL      postgres      postgres
max_index_keys                  32            NULL  user     NULL      32            32
node_id                         1             NULL  user     NULL      1             1
search_path                     public        NULL  user     NULL      public        public
server_version                  9.5.0         NULL  user     NULL      9.5.0         9.5.0
server_version_num              90500         NULL  user     NULL      90500         90500
session_user                    root          NULL  user     NULL      root          root
sql_safe_updates                false         NULL  user     NULL      false         false
standard_conforming_strings     on            NULL  user     NULL      on            on
timezone                        UTC           NULL  user     NULL      UTC           UTC
tracing                         off           NULL  user     NULL      off           off
transaction_isolation           serializable  NULL  user     NULL      serializable  serializable
transaction_priority            normal        NULL  user     NULL      normal        normal
transaction_read_only           off           NULL  user     NULL      off           off
transaction_status              NoTxn         NULL  user     NULL      NoTxn         NoTxn

query TTTTTT colnames
SELECT name, source, min_val, max_val, sourcefile, sourceline FROM pg_catalog.pg_settings
----
name                             source  min_val  max_val  sourcefile  sourceline
application_name                 NULL    NULL     NULL     NULL        NULL
client_encoding                  NULL    NULL     NULL     NULL        NULL
client_min_messages              NULL    NULL     NULL     NULL        NULL
database                         NULL    NULL     NULL     NULL        NULL
datestyle                        NULL    NULL     NULL     NULL        NULL
default_transaction_isolation    NULL    NULL     NULL     NULL        NULL
default_transaction_read_only    NULL    NULL     NULL     NULL        NULL
distsql                          NULL    NULL     NULL     NULL        NULL
experimental_force_lookup_join   NULL    NULL     NULL     NULL        NULL
experimental_opt                 NULL    NULL     NULL     NULL        NULL
extra_float_digits               NULL    NULL     NULL     NULL        NULL
intervalstyle                    NULL    NULL     NULL     NULL        NULL
max_index_keys                   NULL    NULL     NULL     NULL        NULL
node_id                          NULL    NULL     NULL     NULL        NULL
search_path                      NULL    NULL     NULL     NULL        NULL
server_version                   NULL    NULL     NULL     NULL        NULL
server_version_num               NULL    NULL     NULL     NULL        NULL
session_user                     NULL    NULL     NULL     NULL        NULL
sql_safe_updates                 NULL    NULL     NULL     NULL        NULL
standard_conforming_strings      NULL    NULL     NULL     NULL        NULL
timezone                         NULL    NULL     NULL     NULL        NULL
tracing                          NULL    NULL     NULL     NULL        NULL
transaction_isolation            NULL    NULL     NULL     NULL        NULL
transaction_priority             NULL    NULL     NULL     NULL        NULL
transaction_read_only            NULL    NULL     NULL     NULL        NULL
transaction_status               NULL    NULL     NULL     NULL        NULL

# pg_catalog.pg_sequence

statement ok
CREATE DATABASE seq

query OOIIIIIB
SELECT * FROM pg_catalog.pg_sequence
----

statement ok
CREATE SEQUENCE foo

statement ok
CREATE SEQUENCE bar MAXVALUE 10 MINVALUE 5 START 6 INCREMENT 2

query OOIIIIIB colnames
SELECT * FROM pg_catalog.pg_sequence
----
seqrelid    seqtypid  seqstart  seqincrement  seqmax               seqmin  seqcache  seqcycle
1244912846  20        1         1             9223372036854775807  1       1         false
758146164   20        6         2             10                   5       1         false

statement ok
DROP DATABASE seq

statement ok
SET database = constraint_db

# Verify sequences can't be seen from another database.
query OOIIIIIB
SELECT * FROM pg_catalog.pg_sequence
----

## pg_catalog.pg_operator

query OTOOTBBOOOOOOOO colnames
SELECT * FROM pg_catalog.pg_operator where oprname='+' and oprleft='float8'::regtype
----
oid         oprname  oprnamespace  oprowner  oprkind  oprcanmerge  oprcanhash  oprleft  oprright  oprresult  oprcom  oprnegate  oprcode  oprrest  oprjoin
3695865198  +        3572887043    NULL      b        false        false       701      701       701        NULL    NULL       NULL     NULL     NULL

# Verify proper functionality of system information functions.

query TT
SELECT pg_catalog.pg_get_expr('1', 0), pg_catalog.pg_get_expr('1', 0::OID)
----
1  1

query T
SELECT pg_catalog.pg_get_expr('1', 0, true)
----
1

statement ok
SET DATABASE = constraint_db

query OTT
SELECT def.oid, c.relname, pg_catalog.pg_get_expr(def.adbin, def.adrelid)
FROM pg_catalog.pg_attrdef def
JOIN pg_catalog.pg_class c ON def.adrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE n.nspname = 'public'
----
2546105486  t1  12:::INT
2449897171  t3  'FOO':::STRING

# Verify that a set database shows tables from that database for a non-root
# user, when that user has permissions.

statement ok
GRANT ALL ON constraint_db.* TO testuser

user testuser

statement ok
SET DATABASE = 'constraint_db'

query I
SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE schemaname='public'
----
3

user root

# Verify that an unset database shows tables across databases.
# But only those items visible to this user are reported.
# (Tests below show that root sees more).

statement ok
SET DATABASE = ''

query error no database specified
SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public' ORDER BY 1

query error no database specified
SELECT viewname FROM pg_catalog.pg_views WHERE schemaname='public' ORDER BY 1

query error no database specified
SELECT relname FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE nspname='public'

query error no database specified
SELECT conname FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'

query error no database specified
SELECT COUNT(*) FROM pg_catalog.pg_depend

query error no database specified
select 'upper'::REGPROC;

query error no database specified
select 'system.namespace'::regclass

statement ok
SET DATABASE = test

## #13567
## regproc columns display as text but can still be joined against oid columns
query OTO
SELECT p.oid, p.proname, t.typinput
FROM pg_proc p
JOIN pg_type t ON t.typinput = p.oid
WHERE t.typname = '_int4'
----
639449980  array_in  array_in

## #16285
## int2vectors should be 0-indexed
query I
SELECT COUNT(*) FROM pg_catalog.pg_index WHERE indkey[0] IS NULL;
----
0

## Ensure no two builtins have the same oid.
query I
SELECT c FROM (SELECT oid, COUNT(*) as c FROM pg_catalog.pg_proc GROUP BY oid) WHERE c > 1
----

## Ensure that unnest works with oid wrapper arrays

query O
SELECT unnest((SELECT proargtypes FROM pg_proc WHERE proname='split_part'));
----
25
25
20

## TODO(masha): #16769
#statement ok
#CREATE TABLE types(a int8, b int2);

#query I
#SELECT attname, atttypid, typname FROM pg_attribute a JOIN pg_type t ON a.atttypid=t.oid WHERE attrelid = 'types'::REGCLASS;
#attname   atttypid  typname
#a         20        int8
#b         20        int2
