Skip to content

Instantly share code, notes, and snippets.

@flaf
Last active December 19, 2022 17:15
Show Gist options
  • Save flaf/588906382c65fb1e9ae2b1167773bc85 to your computer and use it in GitHub Desktop.
Save flaf/588906382c65fb1e9ae2b1167773bc85 to your computer and use it in GitHub Desktop.

Below, why

  • the pattern \dt sql_features doesn't print the table sql_features (in the schema information_schema),
  • but the pattern \dt pg_cast prints the table pg_cast (in the schema pg_catalog)?
dbnccl03=# \conninfo 
You are connected to database "dbnccl03" as user "pginc" via socket in "/tmp" at port "4900".

# There a table sql_features in the schema information_schema.
dbnccl03=# \dt information_schema.sql_features
                 List of relations
       Schema       |     Name     | Type  | Owner 
--------------------+--------------+-------+-------
 information_schema | sql_features | table | pginc
(1 row)

# But the table is not listed with the pattern `sql_features`.
dbnccl03=# \dt sql_features
Did not find any relation named "sql_features".

# But in this case, why it works with the pattern `pg_cast`?
dbnccl03=# \dt pg_cast
          List of relations
   Schema   |  Name   | Type  | Owner 
------------+---------+-------+-------
 pg_catalog | pg_cast | table | pginc
(1 row)


# Just in case it's relevant here.

dbnccl03=# SHOW search_path;
   search_path   
-----------------
 "$user", public
(1 row)

dbnccl03=# SELECT version();
                                                version                                                 
--------------------------------------------------------------------------------------------------------
 PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5), 64-bit
(1 row)
@flaf
Copy link
Author

flaf commented Dec 19, 2022

Answer:

Related with:

  • this, ie the pg_catalog schema is automatically included in the search path:
In addition to public and user-created schemas, each database contains a pg_catalog schema, which
contains the system tables and all the built-in data types, functions, and operators. pg_catalog is always
effectively part of the search path. If it is not named explicitly in the path then it is implicitly searched
before searching the path's schemas. This ensures that built-in names will always be findable.
However, you can explicitly place pg_catalog at the end of your search path if you prefer to have
user-defined names override built-in names.
  • and this about the \dt command:
supply a pattern or the S modifier to include system objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment