Search code examples
postgresqlpostgresql-9.3case-insensitive

Is it possible to force values of a column to be lowercase


I'm working with PostgreSQL 9.3.

I have a table with a varchar column that I always want to be filled with lowercase strings.

I could use the Postgres lower function before saving my values, but is there instead a way to define this column as a lowercase column?


Solution

  • You can accomplish this with a simple check in the column:

    create table lower_field (
        field1 varchar check (field1 = lower(field1))
        );