2013/2/6 JORGE MALDONADO <[email protected]>:
> I have an UPDATE query with the following general structure:
>
> UPDATE table1 SET (SELECT field FROM table2 WHERE conditions ORDER BY
> order_field LIMIT 1)
>
> Is it possible to assign a default value in case no results are returned by
> the SELECT statement?
One option would be to do something with UNION along these lines:
UPDATE table1 SET field =
(SELECT field FROM table2 WHERE conditions
UNION
SELECT 'default_value' WHERE NOT EXISTS (SELECT field FROM table2
WHERE conditions )
ORDER BY order_field LIMIT 1
)
HTH
Ian Barwick
--
Sent via pgsql-sql mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql