Re: Cast '' (blank) to null date

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Mattis Jiderhamn" <mattias(at)expertsystem(dot)se>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Cast '' (blank) to null date
Date: 2001-07-20 15:58:25
Message-ID: 3749.995644705@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Mattis Jiderhamn" <mattias(at)expertsystem(dot)se> writes:
> I'm trying to create a trigger so that, if I try to insert blank, that is
> '', into a date field it will be converted to null so that I don't get
> ERROR: Bad date external representation ''

I don't think it's possible to do that with a trigger. By the time the
trigger is called, the proposed row has already been formed, so any
input data conversion errors that might occur will already have
occurred.

You'll have to code the substitution on the application side, or perhaps
in the SQL query with a CASE expression.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2001-07-20 15:58:45 Re: multiple lookup per row
Previous Message Tom Lane 2001-07-20 15:47:47 Re: multiple lookup per row