pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gary MacMinn <G.MacMinn@nca.gov.au>
Cc: Thomas Lockhart <lockhart@alumni.caltech.edu>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] nulls and datetime
Date: Mon, 15 Nov 1999 01:10:51 -0500
Message-ID: <15251.942646251@sss.pgh.pa.us> (raw)
In-Reply-To: <s83034c6.078@syd_aux.nca.gov.au>

"Gary MacMinn" <G.MacMinn@nca.gov.au> writes:
> I'm trying to find out if PostgreSQL has a function like NVL that
> replaces null values with a default?

NVL is not in the SQL standard.  But COALESCE is, and you can get
what you want with
	COALESCE(x, value-to-use-if-x-is-null)

I'd recommend updating to 6.5.2 or later before doing much with
COALESCE --- it depends on CASE which was fairly buggy in older
releases.

> I have a table with datetime fields, some of which are null. I'm
> trying to extract the date and time components with the date() and
> time() functions but the null values break these functions.

Hmmm ...

regression=>  SELECT t1, date(d1) from test1; 
ERROR:  Unable to convert null datetime to date
regression=>  SELECT t1, time(d1) from test1; 
ERROR:  Unable to convert null datetime to date

This is undesirable, I agree.  It seems to me that those routines should
just return NULL given NULL input, rather than going out of their way to
break applications.  Thomas, can you defend this behavior?

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <15251.942646251@sss.pgh.pa.us>
Permalink:  ../15251.942646251@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15251.942646251@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, G.MacMinn@nca.gov.au, lockhart@alumni.caltech.edu
  Subject: Re: [SQL] nulls and datetime
  In-Reply-To: <15251.942646251@sss.pgh.pa.us>
  References: <s83034c6.078@syd_aux.nca.gov.au> <15251.942646251@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox