From: | "Mark Fenbers" <Mark(dot)Fenbers(at)noaa(dot)gov> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | default value for select? |
Date: | 2005-05-09 16:57:41 |
Message-ID: | 427F9685.8050104@noaa.gov |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 886 bytes |
Mark.Fenbers.vcf | text/x-vcard | 283 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Philip Hallstrom | 2005-05-09 17:18:04 | Re: default value for select? |
Previous Message | AL ELK | 2005-05-09 14:05:25 | Re: diff value retuns, debug mode and play mode |