PG_ATTRIBUTE
PG_ATTRIBUTE stores information about table columns.
Column |
Type |
Description |
---|---|---|
attrelid |
oid |
Table the column belongs to. |
attname |
name |
Column name. |
atttypid |
oid |
Column type. |
attstattarget |
integer |
Level of statistical details set by ANALYZE for the column.
For scalar data types, attstattarget is both the target number of most common values to collect and the target number of histograms to generate. |
attlen |
smallint |
Copy of the pg_type.typlen of this column's type. |
attnum |
smallint |
Column number. |
attndims |
integer |
For arrays, this value denotes the dimensionality. Otherwise, it is 0. |
attcacheoff |
integer |
Always -1 on disk, but might update to the cached column offset within a row when loaded into memory's row descriptor. |
atttypmod |
integer |
Type-specific data supported during table creation (for example, maximum length of varchar columns). Passed as the third parameter to type-related input and length coercion functions. Typically -1 for types not requiring atttypmod. |
attbyval |
Boolean |
Copy of the pg_type.typbyval of this column's type. |
attstorage |
"char" |
Copy of pg_type.typstorage of this column's type. |
attalign |
"char" |
Copy of pg_type.typalign of this column's type. |
attnotnull |
Boolean |
A NOT NULL constraint. You can modify this column to enable or disable the constraint. |
atthasdef |
Boolean |
Whether the column has a default value, which corresponds to the record in the PG_ATTRDEF catalog that actually defines the value. |
attisdropped |
Boolean |
Whether the column has been dropped and is invalid. If it has been dropped, it still exists in the table but is ignored by the analyzer, making it inaccessible through SQL. |
attislocal |
Boolean |
Whether the column is locally defined within the object. A column can be both locally defined and inherited. |
attcmprmode |
tinyint |
Compression method for a column. The operations are:
|
attinhcount |
integer |
Count of immediate parent tables owning the column. If the number of parent tables owning a column is not zero, the column cannot be deleted or renamed. |
attcollation |
oid |
Collation sequence defined for this column. |
attacl |
aclitem[] |
Column-level access permission control. |
attoptions |
text[] |
Attribute-level options. |
attfdwoptions |
text[] |
Foreign-data wrapper property-level options. |
attinitdefval |
bytea |
Stores the default value expression for this column. Used by ADD COLUMN in row-store tables. |
attkvtype |
tinyint |
KV type of the column. Options:
|
Examples
Query column names and IDs of a specified table. Replace t1 and public with actual table and schema names, respectively.
1 2 3 4 5 6 7 |
SELECT attname,attnum FROM pg_attribute WHERE attrelid=(SELECT pg_class.oid FROM pg_class JOIN pg_namespace ON relnamespace=pg_namespace.oid WHERE relname='t1' and nspname='public') and attnum>0; attname | attnum ------------------+-------- product_id | 1 product_name | 2 product_quantity | 3 (3 rows) |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot