Ошибка «invalid reference to FROM-clause entry for table»

Имеется простейший код:

SELECT t.id FROM t AS u;

Получаю ошибку «invalid reference to FROM-clause entry for table "t"». В чём дело?


Ответы (1 шт):

Автор решения: Ainar-G

При использовании синонимов (англ. «alias»), в запросе нужно использовать только их. Из документации (выделение добавлено):

A substitute name for the FROM item containing the alias. An alias is used for brevity or to eliminate ambiguity for self-joins (where the same table is scanned multiple times). When an alias is provided, it completely hides the actual name of the table or function; for example given FROM foo AS f, the remainder of the SELECT must refer to this FROM item as f not foo. If an alias is written, a column alias list can also be written to provide substitute names for one or more columns of the table.
→ Ссылка