Re: [HACKERS] SELECT...FOR UPDATE OF class_name

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [HACKERS] SELECT...FOR UPDATE OF class_name
Дата
Msg-id 19952.948010166@sss.pgh.pa.us
обсуждение исходный текст
Ответ на SELECT...FOR UPDATE OF class_name  (Kristofer Munn <kmunn@munn.com>)
Ответы Re: [HACKERS] SELECT...FOR UPDATE OF class_name  (Kristofer Munn <kmunn@munn.com>)
Список pgsql-hackers
Kristofer Munn <kmunn@munn.com> writes:
> select 1 from tbl2 t2, tbl1 t1 where t1.id1 = t2.id1 and 
>     t2.id1 = 7 for update of tbl2;

> ERROR:  FOR UPDATE: relation tbl2 not found in FROM clause

I believe the error message is correct; you should have written

select 1 from tbl2 t2, tbl1 t1 where t1.id1 = t2.id1 and t2.id1 = 7 for update of t2;

A lot of people do not realize that writing an alias for a table
in FROM means that as far as all the rest of that query is concerned,
that alias *is* the name of the table.  The original table name is
completely masked by the alias.  This must be so, because one of the
main reasons for the alias facility is to resolve ambiguity when you
are doing self-joins.  Consider
select * from person p1, person p2 where p1.spouse = p2.id;

If you wrote instead
select * from person p1, person p2 where p1.spouse = person.id;

which instance of the person table is being referenced?  SQL resolves
this by treating it as an error: there is no table named person
available from that FROM clause.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Kristofer Munn
Дата:
Сообщение: SELECT...FOR UPDATE OF class_name
Следующее
От: "Ansley, Michael"
Дата:
Сообщение: RE: [HACKERS] pg_dump not in very good shape