Other Functions
PG_GET_EXPR
Overview
The pg_get_expr
function retrieves the internal form of an individual expression, such as the default value for a column.
Syntax
There are two versions of the pg_get_expr
function:
Please see the breakdown of both versions:
-
expr_text
: The expression for which you want to obtain the internal representation. It can be any string value. -
relation_oid
: The OID (Object Identifier) of the table the expression belongs to. It is in integer type. -
pretty_bool
: A boolean value determining whether to format the expression in a more human-readable format (TRUE) or not (FALSE).
Output
Both versions of the pg_get_expr
function return an empty string ""
.
Example
- First, create a sample table named employees.
CREATE TABLE employees (
id INT,
name TEXT,
salary TEXT
);
- Get OID of the table.
SELECT oid FROM pg_class WHERE relname = 'employees';
You will get the OID of the table:
oid
------
1018
- Retrieve the internal form for the
salary
column usingpg_get_expr
.
-- Version 1
SELECT pg_get_expr('salary', 1018);
-- Version 2
SELECT pg_get_expr('salary', 1018, TRUE);
Both return the same value, an empty string ""
.
pg_get_expr
-------------