是的。。你不能在where子句中使用列名。首先了解SQL执行流程。根据你的SQL语句,它将按以下顺序执行。
48 Using column alias in a WHERE clause doesn't work 0 Creating two sub queries using WITH clause 4 PostgreSQL closing connection during requests Hot Network Questions ESTA re entry to USA After banning UNRWA from operating in Gaza, what is the Israeli plan for education in the strip?
ADD [ COLUMN ] column_type [ column_constraint [ ... ] ] DROP [ COLUMN ] column [ RESTRICT | CASCADE ] ALTER [ COLUMN ] column TYPE type [ USING expression ] ALTER [ COLUMN ] column SET DEFAULT expression ALTER [ COLUMN ] column DROP DEFAULT ALTER [ COLUMN ] column { SET | DROP...
"id" AS "User_id" FROM "users" "User" WHERE "User".email=$1 By the way, can't we just always quote all the identifiers (i.e. table names, column names, aliases, etc)? I think this will prevent such problems in it's roots. @pleerock is there any workarounds I can use to...
LIMIT 1 ) nk ON true WHERE p."userId" = c."otherUserId" -- ORDER BY ??? LIMIT 1 ) p ON true -- ... This passes on all columns in the FROM list of the subquery. You must deal out unique column aliases in the nested subqueries, of course, and reference the table alias p ...
Where from_item can be one of: [ ONLY ] table_name [ * ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]( select ) [ AS ] alias [ ( column_alias [, ...] ) ]function_name ( [ argument [, ...] ] )[ AS ] alias [ ( column_alias [, ...] | column_definition...
ARRAY requires just one target column, and creates an array of the target column’s type using any number of rows resulting from the subselect. SubLink被归类为Expr节点,但它实际上不是可执行的;在计划期间,它必须在表达式树中被“子计划”节点替换。SubLink is classed as an Expr node, but it is...
(int)j->jointype);break;}/* Although we could include the pulled-up subqueries in the returned relids, there's no need since upper quals couldn't refer to their outputs anyway. But we *do* need to include the join's own rtindex because we haven't yet collapsed join alias variables...
In PostgreSQL, a column alias can be used along with the ORDER BY, or GROUP BY clause; however, it can't be used with the WHERE or HAVING clause. By default, an alias will be in small letters. However, to specify special symbols, white spaces, mixed-case letters, etc., quotes must...
CTE可用于选择所需的列,然后在CTE上进行过滤,如: