The pg_get_expr function retrieves the internal form of an individual expression, such as the default value for a column.


There are two versions of the pg_get_expr function:

SELECT pg_get_expr('expr_text', relation_oid);

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).


Both versions of the pg_get_expr function return an empty string "".


  1. First, create a sample table named employees.
CREATE TABLE employees (
    id INT,
    name TEXT,
    salary TEXT
  1. Get OID of the table.
SELECT oid FROM pg_class WHERE relname = 'employees';

You will get the OID of the table:

  1. Retrieve the internal form for the salary column using pg_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 "".