From: Keith Worthington <keithw@narrowpathinc.com>
To: Mark Fenbers <Mark.Fenbers@noaa.gov>
Cc: pgsql-sql@postgresql.org
Subject: Re: default value for select?
Date: Mon, 9 May 2005 13:26:55 -0400
Message-ID: <20050509172414.M48914@narrowpathinc.com> (raw)
In-Reply-To: <427F9685.8050104@noaa.gov>
References: <427F9685.8050104@noaa.gov>
On Mon, 09 May 2005 12:57:41 -0400, Mark Fenbers wrote
> I want to update a column in myTable. The value this column is set
> todepends on a nested select statement which sometimes returns 0
> rowsinstead of 1. This is a problem since the column I'm trying to
> updateis set to refuse nulls. Here's a sample:
>
> update myTable set myColumn = (Select altColumn from altTable
> wherealtColumn != 'XXX' limit 1) where myColumn = 'XXX';
>
> MyColumn cannot accept nulls, but sometimes "Select altColumn
> ..."returns 0 rows, and thus, the query fails.
>
> Is there a way to set a default value to be inserted into myColumn
> ifand when "select altColumn ..." returns zero rows?
>
> Mark
Mark,
I do not know if it will work but I would try the COALESCE function.
http://www.postgresql.org/docs/8.0/interactive/functions-conditional.html
Kind Regards,
Keith
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: keithw@narrowpathinc.com, Mark.Fenbers@noaa.gov
Subject: Re: default value for select?
In-Reply-To: <20050509172414.M48914@narrowpathinc.com>
* 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