tags:

views:

22

answers:

1

INFORMIX-SE 7.32:

I'm getting error 360 when I try to execute the following statement:

update transaction
   set transaction.colx = (select tab1.cola from tab1)
 where transaction.num  = (select max(transaction.num) from transaction)
   and transaction.colx IS NULL;

Any ideas?

+2  A: 

You're trying to UPDATE the table transaction and read from the same table using SELECT MAX with the same query. You cannot do that.

Subquery restrictions

In general, you cannot modify a table and select from the same table in a subquery. For example, this limitation applies to statements of the following forms:
DELETE FROM t WHERE ... (SELECT ... FROM t ...);
UPDATE t ... WHERE col = (SELECT ... FROM t ...);
{INSERT|REPLACE} INTO t (SELECT ... FROM t ...);

Amarghosh
@Amarghosh- So is there an alternative method for locating the max(transaction.num) in order to update it?
Frank Computer
@Frank Why don't you run `select max(transaction.num) from transaction` first and use the value in the query.
Amarghosh
@Frank: Amarghosh is correct - there are limitations in SE that are not present in IDS and other more modern and capable DBMS, and this is one of them. With IDS, you could use a SEQUENCE. With SE, you could create a one-row temporary table to hold the maximum and use that in the UPDATE statement. If, as I understand from other questions, you are primarily working with a single-user system, that will be safe enough. If you were dealing with a multi-user system (like most people have to), then you'd have to be a lot more worried about the TOCTOU (time of check, time of use) window for a change.
Jonathan Leffler