当我尝试在 Postgresql 9.2.2 中执行下一个查询时收到错误。
SELECT emp_wallet_periods.employer_id, t.ttl as total, COALESCE(t.imported,0), COALESCE(t.spend, 0), COALESCE(t.available, 0), emp_wallet_periods.year, emp_wallet_periods.month
FROM (
SELECT employer_id,
CAST (date_part('month', to_timestamp(date_created)) AS INTEGER) as month,
CAST (date_part('year', to_timestamp(date_created)) AS INTEGER) as year
FROM z_employer_wallet
WHERE state = 1
GROUP BY 1, 2, 3) as emp_wallet_periods
INNER JOIN get_employers_availability_by_month(emp_wallet_periods.employer_id, emp_wallet_periods.year, emp_wallet_periods.month) as t ON t.employerId = emp_wallet_periods.employer_id
ORDER BY emp_wallet_periods.year DESC, t.available DESC, emp_wallet_periods.month DESC
相同的查询在 Postgresql 9.5.6 中运行完美。
我收到的确切错误消息是:
ERROR: invalid reference to FROM-clause entry for table "emp_wallet_periods" LINE 9: INNER JOIN get_employers_availability_by_month(emp_wallet_p...
^ HINT: There is an entry for table "emp_wallet_periods", but it cannot be referenced from this part of the query.
我错过了什么?
最佳答案
不幸的是,这种语法在 Postgres 9.2 中不可用。 Postgres 9.3. 中引入了用于 FROM 子句子查询和函数调用的 LATERAL 选项
关于php - PostgreSQL 9.2.2。表 "xxx"有一个条目,但不能从这部分查询中引用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51726274/