![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Following query is considered as correct, no "missing from" error has been reported (so, entire table will be updated and "on update" triggers will be fired for every row): update item set obj_id = obj_id where obj_id in (select obj_id where item_point is null order by obj_modified limit 10) Is it a bug? If no, maybe to produce warning in such cases? -- Best regards, Nikolay |
#3
| |||
| |||
|
|
On 12/19/06, Nikolay Samokhvalov <samokhvalov (AT) gmail (DOT) com> wrote: Following query is considered as correct, no "missing from" error has been reported (so, entire table will be updated and "on update" triggers will be fired for every row): update item set obj_id = obj_id where obj_id in (select obj_id where item_point is null order by obj_modified limit 10) Is it a bug? If no, maybe to produce warning in such cases? On 12/18/06, Nikolay Samokhvalov <samokhvalov (AT) gmail (DOT) com> wrote: ok, sorry, I've realized that it's yet another example of "outer reference", Tom will say "read any SQL book" again :-) http://archives.postgresql.org/pgsql...2/msg00115.php |
#4
| |||
| |||
|
|
Is it a bug? If no, maybe to produce warning in such cases? |
#5
| |||
| |||
|
|
Is it a bug? If no, maybe to produce warning in such cases? oups. just thumbled over this as well when i forgot a FROM in a WHERE ... IN (....) and damaged quite some data. the bad query went like this: SELECT * FROM movies.names WHERE mov_id IN (SELECT DISTINCT mov_id WHERE mov_name like '%, %' LIMIT 2) the subselect is missing a FROM <table>. in that case, pgsql seemed to also ignore the LIMIT 2 and returned 3706 records out of ~130000... |
|
no clue which ones :-/ |
#6
| |||
| |||
|
|
oups. just thumbled over this as well when i forgot a FROM in a WHERE ... IN (....) and damaged quite some data. the bad query went like this: SELECT * FROM movies.names WHERE mov_id IN (SELECT DISTINCT mov_id WHERE mov_name like '%, %' LIMIT 2) the subselect is missing a FROM <table>. in that case, pgsql seemed to also ignore the LIMIT 2 and returned 3706 records out of ~130000... and the UPDATE was? |
|
also the limit applies only to the subselect, it has nothing to do with the upper query so the upper query can return more than number of rows specified in the subselect... |
|
LIMIT is often meaningfull only in conjuction with ORDER BY |
#7
| |||
| |||
|
|
oups. just thumbled over this as well when i forgot a FROM in a WHERE ... IN (....) and damaged quite some data. the bad query went like this: SELECT * FROM movies.names WHERE mov_id IN (SELECT DISTINCT mov_id WHERE mov_name like '%, %' LIMIT 2) the subselect is missing a FROM <table>. in that case, pgsql seemed to also ignore the LIMIT 2 and returned 3706 records out of ~130000... and the UPDATE was? that was done by the application with the returned recordset. also the limit applies only to the subselect, it has nothing to do with the upper query so the upper query can return more than number of rows specified in the subselect... IF the subquery would only have returned 2 ids, then there would be at most like +/-10 records affected. each mov_id can hold one or more (usuals up to 5) names. but here, the subquery seemed to return ~3700 distinct mov_ids, thus around 37000 names where damaged by the following programmatical updates instead of only a hands full... |
#8
| |||
| |||
|
|
SELECT * FROM movies.names WHERE mov_id IN (SELECT DISTINCT mov_id WHERE mov_name like '%, %' LIMIT 2) IF the subquery would only have returned 2 ids, then there would be at most like +/-10 records affected. each mov_id can hold one or more (usuals up to 5) names. but here, the subquery seemed to return ~3700 distinct mov_ids, thus around 37000 names where damaged by the following programmatical updates instead of only a hands full... have you tested the query in psql? what results do you get? |
#9
| |||
| |||
|
|
SELECT * FROM movies.names WHERE mov_id IN (SELECT DISTINCT mov_id WHERE mov_name like '%, %' LIMIT 2) the subselect is missing a FROM <table>. in that case, pgsql seemed to also ignore the LIMIT 2 |
#10
| |||
| |||
|
|
SELECT * FROM movies.names WHERE mov_id IN (SELECT DISTINCT mov_id WHERE mov_name like '%, %' LIMIT 2) IF the subquery would only have returned 2 ids, then there would be at most like +/-10 records affected. each mov_id can hold one or more (usuals up to 5) names. but here, the subquery seemed to return ~3700 distinct mov_ids, thus around 37000 names where damaged by the following programmatical updates instead of only a hands full... have you tested the query in psql? what results do you get? the data is damaged so the result isn't the same... regenearting it now from a backup. from first tests i would say it returned records with names that match the WHERE in the subselect. i guess what happened is: it took each record in movies.names, then run the subquery for that record which resulted in "WHERE mov_id IN (mov_id)" = true for records with a ', ' in the name and "WHERE mov_id IN ()" = false for all others. - thomas ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |
![]() |
| Thread Tools | |
| Display Modes | |
| |