PostgreSQL parse_ident() Function

The PostgreSQL parse_ident() function splits the argument into an array of identifiers, and quotes around individual identifiers will be removed if possible.

If strict mode is enabled, additional characters after the last identifier will cause an error. If strict mode is not enabled, parse_ident() the extra characters will be ignored.

parse_ident() Syntax

This is the syntax of the PostgreSQL parse_ident() function:

parse_ident (qualified_identifier)

or

parse_ident (qualified_identifier, strict_mode)

Parameters

qualified_identifier

Required. Text type. The string that is a qualified identifier.

strict_mode

Optional. Boolean type. It indicates whether to enable strict mode. The default is true.

Return value

The PostgreSQL parse_ident() function returns an array containing all the identifiers splited from qualified_identifier.

The following cases will case an error:

  • qualified_identifier does not start with a valid identifier.
  • In strict mode, there are additional characters after the last identifier.

If the parameter is NULL, the function will return NULL.

parse_ident() Examples

Basic Usage

This example shows how to usethe parse_ident() function to split qualified identifiers.

SELECT parse_ident('"SomeSchema".someTable');
      parse_ident
------------------------
 {SomeSchema,sometable}

If the quotation marks around individual identifier cannot be removed, the quotation marks are preserved:

SELECT parse_ident('"SomeSchema"."some Table"');
        parse_ident
---------------------------
 {SomeSchema,"some Table"}

Strict Mode

By default, parse_ident() uses strict mode, that is, you must use a qualified identifier as a parameter,otherwise an error will occur.

SELECT parse_ident('"SomeSchema"."someTable"Error');

This cases an error: “Error: String is not a valid identifier: ““SomeSchema”.“someTable"Error””.

If parse_ident() disable strict mode, the last bad character is ignored. We can disable strict mode by passing false to the strict_mode parameter. As follows:

SELECT parse_ident('"SomeSchema"."someTable"Error', false);
      parse_ident
------------------------
 {SomeSchema,someTable}

The unqualified identifier Error is ignored.