gpt4 book ai didi

sql - Postgres : What is the query 'select * from user' actually doing?

转载 作者:行者123 更新时间:2023-11-29 11:14:31 25 4
gpt4 key购买 nike

在 psql 中,如果键入“select * from user”,您将得到类似以下内容的返回:

 current_user 
--------------
postgres

在此上下文中用户是什么?

最佳答案

在此上下文中,user 是保留的内部 Postgres 函数,表示当前登录到数据库的用户。

这个查询也可以写成:

选择用户;

这应该会产生相同的结果。请注意,如果您想实际引用或创建一个名为 user 的表,则必须使用引号或完全限定它所在的模式。例如:

CREATE TABLE "user"
(
id int2 not null
);

会工作但是:

CREATE TABLE user
(
id int2 not null
);

会产生错误。

这里是其他系统信息函数的引用:

http://www.postgresql.org/docs/9.0/static/functions-info.html

关于sql - Postgres : What is the query 'select * from user' actually doing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9010634/

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