PhpPgAdmin 创建视图时出现语法错误
我试图在 PhpPgAdmin (PostGreSQL db) 中创建一个视图,该视图具有以下 SQL 语句:
DELETE FROM myTable WHERE myTable.error IS NULL;
PhpPgAdmin 给我以下错误:
错误:第 59 字符处或附近的“DELETE”处存在语法错误 在声明中: 创建或替换视图“Schema1”。“删除空错误”AS DELETE FROM myTable WHERE myTable.error IS NULL;
据我所知,这个 SQL 语句是有效的,并且我拥有该表的删除权限。视图中不允许使用 DELETE 语句吗?有什么想法我做错了吗?
I am attempting to create a View in PhpPgAdmin (PostGreSQL db) which has the following SQL statement:
DELETE FROM myTable WHERE myTable.error IS NULL;
PhpPgAdmin gives me the following error:
ERROR: syntax error at or near "DELETE" at character 59
In statement:
CREATE OR REPLACE VIEW "Schema1"."Delete empty errors" AS DELETE FROM myTable WHERE myTable.error IS NULL;
As far as I can tell this SQL statement is valid, and I have delete privileges for the table. Is the DELETE statement not allowed in Views? Any ideas what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
视图仅用于显示 SELECT 语句中的数据(通常当 SELECT 很复杂时)。视图不能包含 DELETES、UPDATES 或 INSERTS。
也许您想要一个函数?
编辑:正如 OMG Ponies 指出的那样,您可以拥有可更新的视图,但这就是您向现有视图发出 DELETE,然后使用 RULE 将查询重写为 DELETE 的地方。
并且请不要包装函数调用来执行 DELETE 作为视图中的副作用。这是出乎意料的,每次发生这种情况,耶稣都会射杀一只小狗。
Views are used to display the data from SELECT statements only (usually when the SELECT is complex). Views cannot contain DELETES, UPDATES, or INSERTS.
Perhaps you want a function?
EDIT: As OMG Ponies points out, you can have updateable views, but thats where you would issue a DELETE to an existing view and then use a RULE to rewrite the query as a DELETE.
And please, please don't wrap a function call to do a DELETE as a side effect in a view. Its unexpected and Jesus shoots a puppy every time this happens.