Re: Setting a field to default if blank value

From: Dennis Gearon <gearond(at)cvc(dot)net>
To: Robert Fitzpatrick <robert(at)webtent(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Setting a field to default if blank value
Date: 2003-04-28 17:26:07
Message-ID: 3EAD642F.4060303@cvc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you mean blank like '', then if the field is a string, it would be normal behavior as is.

If it's any other type of field, set a default value and it will take the place of a non existent value.

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?
>
> --
> Robert
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Tessier 2003-04-28 17:26:55 Selecting the most recent date
Previous Message Dennis Gearon 2003-04-28 17:24:15 Re: problems restoring 7.2.1 dump to 7.3.2