gpt4 book ai didi

sql - "SELECT INTO"是做什么的?

转载 作者:行者123 更新时间:2023-11-29 11:36:05 28 4
gpt4 key购买 nike

我正在阅读 sql 代码,其中一行看起来像这样:

SELECT INTO _user tag FROM login.user WHERE id = util.uuid_to_int(_user_id)::oid;

这到底是做什么的?使用 SELECT INTO 的通常方法需要在 SELECT 标记之后指定要选择的列,例如

SELECT * INTO _my_new_table WHERE ...;

数据库是postgresql。

最佳答案

这一行必须出现在 PL/pgSQL 函数中。在这种情况下,tag 列的值被分配给变量 _user

根据documentation :

Tip: Note that this interpretation of SELECT with INTO is quite different from PostgreSQL's regular SELECT INTO command, wherein the INTO target is a newly created table.

The INTO clause can appear almost anywhere in the SQL command. Customarily it is written either just before or just after the list of select_expressions in a SELECT command, or at the end of the command for other command types. It is recommended that you follow this convention in case the PL/pgSQL parser becomes stricter in future versions.

关于sql - "SELECT INTO"是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31105738/

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