From: | Scott Marlowe <smarlowe(at)g2switchworks(dot)com> |
---|---|
To: | "Roderick A(dot) Anderson" <raanders(at)tsmg(dot)us> |
Cc: | Pg General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: default column value using a function, trigger, or |
Date: | 2005-05-03 22:42:51 |
Message-ID: | 1115160171.13303.1536.camel@state.g2switchworks.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, 2005-05-03 at 17:31, Roderick A. Anderson wrote:
> I am trying to come up with a method to have a default value for a
> column based on a function and other columns. I'm hoping ( well not too
> much ) that what I figure out here will apply to MS SQL Server as I am
> stuck using it unless I can prove there ain't no way it's going to
> happen. ( Now that the embarrassment of being stuck using SQL Server is
> out of the way. )
>
> I'd like to populate a column with the md5 of ColA || ':' || ColB || ':'
> || ColC. A search of the archives ( with the terms I was using )
> didn't turn up anything useful.
>
> Would this be a function or a trigger?
This will be an after trigger function (everything's a function! woot!
hehe. seriously though, all triggers are functions, but not all
functions are triggers, in postgresql land).
Basically, you'll need an after trigger that updates the md5 field with
that cola/b/c bit you've got up there. Not much to it really.
One of the examples on this page ought to help:
http://www.postgresql.org/docs/8.0/static/plpgsql-trigger.html
From | Date | Subject | |
---|---|---|---|
Next Message | Jim C. Nasby | 2005-05-03 22:45:59 | Very interesting article about the future of databases |
Previous Message | Roderick A. Anderson | 2005-05-03 22:31:26 | default column value using a function, trigger, or whatever |