Auto-uppercase inserted column

Started by Bruce Momjianalmost 26 years ago3 messagesgeneral
Jump to latest
#1Bruce Momjian
bruce@momjian.us

Is there a way to automatically uppercase a column upon insert or
update?

I don't think rules can do that because of the problem of recursion.
The only way I think it can be done is using triggers. Is that correct?

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#2Jurgen Defurne
defurnj@glo.be
In reply to: Bruce Momjian (#1)
Re: Auto-uppercase inserted column

Bruce Momjian wrote:

Is there a way to automatically uppercase a column upon insert or
update?

I don't think rules can do that because of the problem of recursion.
The only way I think it can be done is using triggers. Is that correct?

Since triggers are available in postgreSQL, that should be the way, yes.
You have to have access to the NEW values in your trigger, and then you
should say something like
NEW.field := upper(NEW.field) ;

In older database systems this would be done in the entry system, but
then you have a coupling between your application and the database.

Good luck.

Jurgen Defurne
defurnj@glo.be

#3Bruce Momjian
bruce@momjian.us
In reply to: Jurgen Defurne (#2)
Re: Auto-uppercase inserted column

Bruce Momjian wrote:

Is there a way to automatically uppercase a column upon insert or
update?

I don't think rules can do that because of the problem of recursion.
The only way I think it can be done is using triggers. Is that correct?

Since triggers are available in postgreSQL, that should be the way, yes.
You have to have access to the NEW values in your trigger, and then you
should say something like
NEW.field := upper(NEW.field) ;

In older database systems this would be done in the entry system, but
then you have a coupling between your application and the database.

Thanks. I was just seeking confirmation for my book. I expected
triggers where the only way.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026