postgres:查询“从用户选择*”的实际作用是什么? [英] postgres: What is the query 'select * from user' actually doing?

查看:99
本文介绍了postgres:查询“从用户选择*”的实际作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在psql中,如果键入从用户中选择*,您将得到类似以下的内容:

In psql, if one types 'select * from user' you'll get something like the following back:

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

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

What is user in this context?

推荐答案

在这种情况下, user 是内部保留的Postgres函数,代表当前登录到数据库的用户。

In this context, user is a reserved internal Postgres function that represents the current user logged in to the database.

此查询也可以写为:

SELECT用户;

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

Which should yield the same thing. Note, if you want to actually reference or create a table named user you'll have to use quotes, or fully qualify the schema it lives in. For example:

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

可以使用,但是:

CREATE TABLE user
(
  id int2 not null
);

会产生错误。

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

Here's a reference for other system information functions:

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

这篇关于postgres:查询“从用户选择*”的实际作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆