Skip site navigation (1) Skip section navigation (2)

Re: Trigger to force fields to lowercase at insert/update

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Leonardo Boiko <leoboiko(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Trigger to force fields to lowercase at insert/update
Date: 2006-04-29 20:19:24
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Wed, Apr 26, 2006 at 12:52:55 -0700,
  Leonardo Boiko <leoboiko(at)gmail(dot)com> wrote:
> Suppose I have a bunch of fields in different tables which I'd like to
> always force to lowercase (since they represent case-insensitive data).
> Suppose I want to do it at SQL level, not application level.  If the
> user say "INSERT INTO foo VALUES ('Abc')", I want to really insert
> 'abc'.  Is there an elegant way of doing this? Some kind of trigger,
> maybe? I have no experience with triggers or pl/sql, but I couldn't
> come up with a solution general enough to be reused in multiple places.
> Or is the premise a bad idea?

You can use a before trigger to change the value of the column when it
is inserted or updated.

In response to

pgsql-novice by date

Next:From: operationsengineer1Date: 2006-04-29 21:33:01
Subject: PGAdmin3 Permisions
Previous:From: Andreas KretschmerDate: 2006-04-29 20:19:18
Subject: Re: running pg_dumpall as a cron job

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group