force varchar column to be lowercase

Can I use a check constraint, or something other than a function to force a
column to be lowercase only?


Thx in advance

--
Sent via pgsql-admin mailing list (pgsql-admin [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Kevin Kempter [ Di, 28 Juli 2009 05:33 ] [ ID #2010050 ]

Re: force varchar column to be lowercase

Kevin Kempter schrieb:
> Can I use a check constraint, or something other than a function to force a
> column to be lowercase only?
>
>
> Thx in advance

try to use regexp in your CHECK CONSTRAINT:

CHECK (column::bpchar ~ '^[a-z]+$'::bpchar::text)

Cheers

Andy

--
Sent via pgsql-admin mailing list (pgsql-admin [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Andreas Wenk [ Di, 28 Juli 2009 12:15 ] [ ID #2010052 ]

Re: force varchar column to be lowercase

On Tue, Jul 28, 2009 at 11:15 AM, Andreas
Wenk<a.wenk [at] netzmeister-st-pauli.de> wrote:
> Kevin Kempter schrieb:
>>
>> Can I use a check constraint, or something other than a function to force
>> a column to be lowercase only?
>>
>>
>> Thx in advance
>
> try to use regexp in your CHECK CONSTRAINT:
>
> CHECK (column::bpchar ~ '^[a-z]+$'::bpchar::text)

Better would be CHECK (column = tolower(column)) which won't fail on
non-letters and will work in non-C locales

--
greg
http://mit.edu/~gsstark/resume.pdf

--
Sent via pgsql-admin mailing list (pgsql-admin [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Greg Stark [ Di, 28 Juli 2009 12:50 ] [ ID #2010053 ]

Re: force varchar column to be lowercase

Greg Stark schrieb:
> On Tue, Jul 28, 2009 at 11:15 AM, Andreas
> Wenk<a.wenk [at] netzmeister-st-pauli.de> wrote:
>> Kevin Kempter schrieb:
>>> Can I use a check constraint, or something other than a function to force
>>> a column to be lowercase only?
>>>
>>>
>>> Thx in advance
>> try to use regexp in your CHECK CONSTRAINT:
>>
>> CHECK (column::bpchar ~ '^[a-z]+$'::bpchar::text)
>
> Better would be CHECK (column = tolower(column)) which won't fail on
> non-letters and will work in non-C locales

yes . but Kevin was asking for a way without a function. And by the way - it should read
lower instead of tolower ... or am I wrong?

Cheers

Andy

--
Sent via pgsql-admin mailing list (pgsql-admin [at] postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Andreas Wenk [ Di, 28 Juli 2009 13:11 ] [ ID #2010054 ]
Datenbanken » gmane.comp.db.postgresql.admin » force varchar column to be lowercase

Vorheriges Thema: WAL backup
Nächstes Thema: create of partition table slow