Received: from aventurine.sge.net (aventurine.sge.net [152.91.14.25]) by hub.org (8.9.3/8.9.3) with ESMTP id AAA64854 for ; Wed, 17 Nov 1999 00:19:39 -0500 (EST) (envelope-from G.MacMinn@nca.gov.au) Received: from cadmium.sge.net (cadmium.sge.net [152.91.9.5]) by aventurine.sge.net (8.9.3/8.9.3) with ESMTP id QAA44644 for ; Wed, 17 Nov 1999 16:19:35 +1100 (EST) Received: (from uucp@localhost) by cadmium.sge.net (8.9.3/8.9.3) id QAA24452 for ; Wed, 17 Nov 1999 16:19:33 +1100 (EST) Received: from nodnsquery(10.1.2.11) by cadmium.sge.net via smap (V5.0) id xma024417; Wed, 17 Nov 99 16:19:27 +1100 Received: from amber (amber-int2.sge.net [10.1.2.254]) by kryptonite.sge.net (8.9.3/8.9.3) with SMTP id QAA16299 for ; Wed, 17 Nov 1999 16:19:27 +1100 (EST) Message-Id: X-Mailer: Novell GroupWise 5.2 Date: Wed, 17 Nov 1999 16:16:37 +1100 From: "Gary MacMinn" To: tgl@sss.pgh.pa.us Cc: lockhart@alumni.caltech.edu, pgsql-sql@postgreSQL.org Subject: Re: [SQL] nulls and datetime Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Disposition: inline Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id AAA65220 Tom, Thanks for that. Coalesce worked like a ripper. It even forced me to update the database to 6.5.2. I'd been putting it off for a while. Gary >>> Tom Lane 15/11/99 16:10:51 >>> "Gary MacMinn" 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 ************