gpt4 book ai didi

sql - "DELETE FROM table"的 output_expression 有什么作用?

转载 作者:行者123 更新时间:2023-11-29 11:15:01 24 4
gpt4 key购买 nike

我最近遇到了一个怪事。以下是有效的 SQL:

DELETE FROM customer *;

PostgreSQL 文档 DELETE表示星号是 output_expression 的可能值:

An expression to be computed and returned by the DELETE command after each row is deleted. The expression can use any column names of the table or table(s) listed in USING. Write * to return all columns.

我在有星号和没有星号的情况下都试过了,看不出有什么不同。事实上,我可以在表名后面加上任何一个词,它就被接受了。它甚至不必是实际的列名。不会返回任何额外的内容。

db=> DELETE FROM customer wheeeeeee;
DELETE 19

那么它有什么作用,我可以用它做什么?

问题 also posted on the PostgreSQL mailing list .

最佳答案

星号不是 output_expression,为此您必须使用RETURNING 关键字。它是一种旧的、过时的语法,用于在查询中包含子表。 (它记录的最后一个版本似乎是 PostgreSQL 8.1 。由于语法仍然有效,它是一个文档错误,正如 Tom Lane 在下面链接的帖子中指出的那样。)

从 PostgreSQL 7.1 开始,这是默认设置(除非 sql_inheritance 设置为关闭)并且 ONLY 关键字用于相反的情况,因此 * 不是很有用。

参见 this explanatory post from Tom Lane on the PostgreSQL mailing list .

关于sql - "DELETE FROM table"的 output_expression 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12445284/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com