Re: Setting a field to default if blank value

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Robert Fitzpatrick <robert(at)webtent(dot)com>
Cc: <gearond(at)cvc(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Setting a field to default if blank value
Date: 2003-04-28 19:44:44
Message-ID: Pine.LNX.4.33.0304281327150.13935-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 28 Apr 2003, Robert Fitzpatrick wrote:

> > Robert Fitzpatrick wrote:
> > > Looking for the best way of handling this, would like to do
> > it in the
> > > database and not in my apps. I set a field to 'Not Null', but if a
> > > blank value comes in, the field will accept it as just
> > that, a blank
> > > string. How can avoid this using a trigger or function? I thought
> > > about a function that would check the field and then place
> > a trigger,
> > > but that gets to be a lot of functions and triggers for different
> > > fields. Is there a way to pass a field name to the function? (in
> > > plpgsql)
> > >
> > > Or what is the best way to handle this for many different fields in
> > > many tables?
>
> > If you mean blank like '', then if the field is a string, it
> > would be normal behavior as is.
> >
>
> Yes, they are strings (varchar). Know the best way to handle it?

Can a plpgsql function "walk" the fields of an insert / update and replace
every '' with the keyword DEFAULT? I would think that would be the
answer. You'd need to be in 7.3 for DEFAULT to work. In 7.2 I'm not sure
how you'd set a default on '' though.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message afterz 2003-04-28 20:08:29 Implementation Plataform
Previous Message Jimmie H. Apsey 2003-04-28 19:21:38 Re: Postgres client/server parameters?