Re: default value for select?

From: "Keith Worthington" <keithw(at)narrowpathinc(dot)com>
To: "Mark Fenbers" <Mark(dot)Fenbers(at)noaa(dot)gov>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: default value for select?
Date: 2005-05-09 17:26:55
Message-ID: 20050509172414.M48914@narrowpathinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tony Wasson 2005-05-09 17:30:53 Re: default value for select?
Previous Message Philip Hallstrom 2005-05-09 17:18:04 Re: default value for select?