Skip to main content

Overview

The pg_attribute stores information about table columns. It mimics the pg_attribute PostgreSQL system catalog.

Columns

This table is designed for compatibility with tools that require PostgreSQL system tables, so it mostly has dummy data. Please note that not all columns in pg_attribute are applicable to every type of relation
The following columns are available for querying in pg_attribute:

Example

Retrieving Column Information for All Tables

  1. This example queries the pg_attribute to retrieve information about all columns across all tables in the database:
If your database has many tables, the result could be quite long. You can manage the output by filtering specific criteria using WHERE clauses or by limiting the number of rows with LIMIT clauses

Filtering Columns

  1. Create a new table:
  1. To get the OID (Object Identifier) of the books table, run the pg_class.oid query:
  1. It will return the books table with its OID:
  1. To filter columns, we need to utilize the pg_attribute with WHERE clause:
  1. The output should provide you with columns of the books table that you’ve just created:

Joining pg_attribute with pg_class for Table and Column Names

  1. In this example, a join operation with pg_class is performed to include the name of the table (relname):
  1. You will receive both table and column details in a single query result: