Skip site navigation (1) Skip section navigation (2)

Re: UPDATE query based on a SELECT command.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: UPDATE query based on a SELECT command.
Date: 2012-01-28 19:12:44
Message-ID: 26560.1327777964@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
JORGE MALDONADO <jorgemal1960(at)gmail(dot)com> writes:
> Let's suppose that I have an UPDATE query which includes a SELECT as part
> of it as follows:

> UPDATE table1
> SET field1 = (SELECT fieldx FROM table2 WHERE .........)

> What happens if the result of the SELECT command does not return any row?

A scalar subquery that returns no rows has a result of NULL.  This is
not specific to whether it's used in UPDATE.  See
http://www.postgresql.org/docs/9.1/static/sql-expressions.html#SQL-SYNTAX-SCALAR-SUBQUERIES

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Craig BoydDate: 2012-01-28 19:16:44
Subject: Re: PostgreSQL v8 & v9 on the same XP machine - SOLVED
Previous:From: JORGE MALDONADODate: 2012-01-28 18:54:30
Subject: UPDATE query based on a SELECT command.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group