select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Unsupported versions: 7.1
Historical version. PostgreSQL 7.1 reached end of support in April 2006. See the current manual for supported releases.

7.5. Functional Indices

For a functional index, an index is defined on the result of a function applied to one or more columns of a single table. Functional indices can be used to obtain fast access to data based on the result of function calls.

For example, a common way to do case-insensitive comparisons is to use the lower:

SELECT * FROM test1 WHERE lower(col1) = 'value';
In order for that query to be able to use an index, it has to be defined on the result of the lower(column) operation:
CREATE INDEX test1_lower_col1_idx ON test1 (lower(col1));

The function in the index definition can take more than one argument, but they must be table columns, not constants. Functional indices are always single-column (namely, the function result) even if the function uses more than one input field; there cannot be multi-column indices that contain function calls.

Tip: The restrictions mentioned in the previous paragraph can easily be worked around by defining custom functions to use in the index definition that call the desired function(s) internally.

Report a documentation issue

Read the upstream documentation. For corrections, first check the current manual.