postgres:查询'select*from user'究竟在做什么?

rpk*_*lly 11 sql postgresql

在psql中,如果有人输入'select*from user',你会得到类似下面的内容:

 current_user 
--------------
 postgres
Run Code Online (Sandbox Code Playgroud)

在这种情况下用户是什么?

Mik*_*sen 18

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

此查询也可以写为:

SELECT user;

哪个应该产生相同的东西.请注意,如果您想要实际引用或创建一个名为的表,user您必须使用引号,或者完全限定它所在的模式.例如:

CREATE TABLE "user"
(
  id int2 not null
);
Run Code Online (Sandbox Code Playgroud)

会工作但是:

CREATE TABLE user
(
  id int2 not null
);
Run Code Online (Sandbox Code Playgroud)

会产生错误.

以下是其他系统信息功能的参考:

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