sql – “SELECT INTO”有什么作用?

我正在读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函数内部.在该上下文中,列标记的值被赋给变量_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.

点赞