| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 09/12/2008 16:55:17
|
Don_N
New member
Joined: 03/12/2008 17:15:20
Messages: 9
Offline
|
create table t1 (c1 int, c2 int);
create table t2 (c1 int, c2 int);
update t1
set c2 = t2.c2
from t2
where t2.c1 = t1.c1
Result:
SQLException: ERROR: Encountered "from" at line 1, column 26.
Was expecting one of:
<EOF>
"WHERE" ...
"!" ...
";" ...
"," ...
"::" ...
"+" ...
"-" ...
"||" ...
"*" ...
"/" ...
"MOD" ...
"DIV" ...
"%" ...
"&" ...
"|" ...
"#" ...
"<<" ...
">>" ...
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 10/12/2008 09:18:24
|
Mason_S
Senior member
Joined: 01/04/2008 09:03:08
Messages: 366
Offline
|
Hi Don,
You need to use syntax like this:
update t1
set c2 =
(select t2.c2
from t2
where t2.c1 = t1.c1);
Regards,
Mason Sharp
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 10/12/2008 12:35:01
|
Don_N
New member
Joined: 03/12/2008 17:15:20
Messages: 9
Offline
|
Wouldn't that be slow when updating multiple columns which is my common update scenario, or are there optimizations to support this?
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 11/12/2008 12:27:30
|
Mason_S
Senior member
Joined: 01/04/2008 09:03:08
Messages: 366
Offline
|
Hi Don,
I have added multi-column correlated update as a new feature request in our tracking system.
Regards,
Mason
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 12/12/2008 15:07:01
|
Don_N
New member
Joined: 03/12/2008 17:15:20
Messages: 9
Offline
|
Hi Mason,
Your suggested workaround does work, but fails when a where clause is needed to reduce the rows to be updated. For example:
update t1
set c2 = (select t2.c2 from t2 where t2.c1 = t1.c1)
where exists (select * from t2 where t2.c1 = t1.c1);
Result:
SQLException: ERROR: Failed To Get Results For ( SQL , NodeURL) : ( SELECT ( SELECT "t2"."c2" From "t2" WHERE ("t2"."c1" = "TMPTT433_1"."c1")) as "EXPRESSION1", "c1" as "c1_old", "c2" as "c2_old" FROM "TMPTT433_1" ) eQS Node 13 has aborted execution, cause is: java.sql.SQLException : ERROR: column "c2" does not exist
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 14/12/2008 20:34:36
|
Mason_S
Senior member
Joined: 01/04/2008 09:03:08
Messages: 366
Offline
|
Hi Don,
That does indeed look like a problem.
We will investigate.
Regards,
Mason
|
|
|
 |
|
|