PhpPgAdmin 创建视图时出现语法错误

发布于 2024-09-07 16:10:07 字数 391 浏览 6 评论 0原文

我试图在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失与倦" 2024-09-14 16:10:07

视图仅用于显示 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文