X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B62F153E53 for ; Mon, 9 May 2005 13:58:04 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51162-10 for ; Mon, 9 May 2005 16:57:58 +0000 (GMT) Received: from werhmsg.werh.noaa.gov (werhmsg.werh.noaa.gov [198.206.32.236]) by svr1.postgresql.org (Postfix) with ESMTP id 7665D534E2 for ; Mon, 9 May 2005 13:57:57 -0300 (ADT) Received: from [198.206.42.50] ([198.206.42.50]) by werhmsg.werh.noaa.gov (Netscape Messaging Server 4.15) with ESMTP id IG8F4L00.11O for ; Mon, 9 May 2005 12:57:57 -0400 Message-ID: <427F9685.8050104@noaa.gov> Date: Mon, 09 May 2005 12:57:41 -0400 From: "Mark Fenbers" Organization: DoC/NOAA/NWS/OHRFC User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: default value for select? Content-Type: multipart/mixed; boundary="------------090904020309000109020002" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.089 tagged_above=0 required=5 tests=AWL, HTML_30_40, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200505/88 X-Sequence-Number: 21401 This is a multi-part message in MIME format. --------------090904020309000109020002 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit I want to update a column in myTable.  The value this column is set to depends on a nested select statement which sometimes returns 0 rows instead of 1.  This is a problem since the column I'm trying to update is set to refuse nulls.  Here's a sample:

update myTable set myColumn = (Select altColumn from altTable where altColumn != '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 if and when "select altColumn ..." returns zero rows?

Mark
--------------090904020309000109020002 Content-Type: text/x-vcard; charset=utf-8; name="Mark.Fenbers.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Mark.Fenbers.vcf" begin:vcard fn:Mark Fenbers n:Fenbers;Mark org:DoC/NOAA/NWS/OHRFC adr:;;1901 South SR 134;Wilmington;OH;45177-9708;USA email;internet:Mark.Fenbers@noaa.gov title:Sr. HAS Meteorologist tel;work:937-383-0430 x246 x-mozilla-html:TRUE url:http://weather.gov/ohrfc version:2.1 end:vcard --------------090904020309000109020002--