Common table expression,WITH clause in PostgreSQL ;ERROR: relation “stkpos” does not exist

纵然是瞬间 提交于 2019-12-11 09:58:47

问题


for example the following is my query

WITH stkpos as (
select * from mytbl
),
updt as (
update stkpos set field=(select sum(fieldn) from stkpos)
)
select * from stkpos

ERROR: relation "stkpos" does not exist


回答1:


Unlike MS-SQL and some other DBs, PostgreSQL's CTE terms are not treated like a view. They're more like an implicit temp table - they get materialized, the planner can't push filters down into them or pull filters up out of them, etc.

One consequence of this is that you can't update them, because they're a copy of the original data, not just a view of it. You'll need to find another way to do what you want.

If you want help with that you'll need to post a new question that has a clear and self contained example (with create table statements, etc) showing a cut down version of your real problem. Enough to actually let us understand what you're trying to accomplish and why.



来源:https://stackoverflow.com/questions/24052356/common-table-expression-with-clause-in-postgresql-error-relation-stkpos-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!