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 7BDFA53E68 for ; Mon, 9 May 2005 14:27:31 -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 58084-01 for ; Mon, 9 May 2005 17:27:26 +0000 (GMT) Received: from mail.99main.com (mail.99main.com [208.28.184.11]) by svr1.postgresql.org (Postfix) with ESMTP id A4F5053E5E for ; Mon, 9 May 2005 14:27:25 -0300 (ADT) Received: from 99main.com (localhost [127.0.0.1]) by mail.99main.com (8.12.8+Sun/8.12.8) with ESMTP id j49HQtLS009203; Mon, 9 May 2005 13:26:56 -0400 (EDT) From: "Keith Worthington" To: "Mark Fenbers" Cc: pgsql-sql@postgresql.org Reply-To: KeithW@narrowpathinc.com Subject: Re: default value for select? Date: Mon, 9 May 2005 13:26:55 -0400 Message-Id: <20050509172414.M48914@narrowpathinc.com> In-Reply-To: <427F9685.8050104@noaa.gov> References: <427F9685.8050104@noaa.gov> X-Mailer: Open WebMail 2.50 20050106 X-OriginatingIP: 68.235.22.242 (npkeithw) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.01 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/89 X-Sequence-Number: 21402 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