PostgreSQL 中有“AS”命令吗?
我想知道 postgres 是否有像 AS
这样的命令。有谁知道postges有这个能力吗?我试图用谷歌搜索它,但对谷歌来说这是一个非常困难的问题:PI想要制作一个选择语句并将其存储为新的表名称。我想说的是:
SELECT subj, user AS 'new' FROM table_name;
I'm wondering if there is a command like AS
for postgres. Does anyone know if postges has this ability? I've tried to google it but it's a very difficult question to google :P I want to make a select statement and store it as a new table name. I want to say something like:
SELECT subj, user AS 'new' FROM table_name;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
是的。它是 PostgreSQL 中保留的 SQL 关键字。请参阅链接文档页面上的表 C-1。
它通常与列标签。
Yes. It's a reserved SQL key word in PostgreSQL. See Table C-1 at the linked documentation page.
It's typically used with column labels.
这样,您的新桌子就准备好了。
So, your new table will be ready.
“我想创建一条 select 语句并将其存储为新的表名”--
"I want to make a select statement and store it as a new table name" --
如果您不想在架构中留下任何更改,您可以执行以下操作 -
If you don't want to leave any changes in the schema, you can do something like this-
SELECT field AS new_field FROM table WHERE ...;
VIEW
并执行以下操作:CREATE OR REPLACE VIEW new_view AS;
SELECT field AS new_field FROM table WHERE ...;
VIEW
and do that:CREATE OR REPLACE VIEW new_view AS <QUERY>;
以我的方式,您可以为字段创建别名并创建视图来存储它。它就像桌子一样。
从 table_name 中选择新的主题、用户;
通过使用上面的查询可以获取 subj 和 new 作为字段。
并创建视图。
创建或替换 view_name 为
从 table_name 中选择新的主题、用户;
只需致电
选择视图名称;
In my way, you can do alias for the field and create view to store it. which ll act like table.
select subj, user as new from table_name;
By using the above query can get subj and new as a field.
And create view.
create or replace view_name as
select subj, user as new from table_name;
And just call
select view_name;
在 PostgreSQL 中,您可以使用或不使用
AS
创建列或表的别名。例如,您创建
person
表,然后向其中插入 2 行,如下所示:现在,您可以创建以下别名
f_n
和l_n
first_name
和last_name
列分别带或不带AS
如下所示:然后,您可以得到如下结果:
并且,您可以创建别名
p
,person
表的f_n
和l_n
,first_name
和last_name
列分别有或没有AS
如下所示:然后,可以得到如下结果:
In PostgreSQL, you can create the alias of a column or table with or without
AS
.For example, you create
person
table, then insert 2 rows into it as shown below:Now, you can create the aliases
f_n
andl_n
offirst_name
andlast_name
column respectively with or withoutAS
as shown below:Then, you can get the result below:
And, you can create the aliases
p
,f_n
andl_n
ofperson
table,first_name
andlast_name
column respectively with or withoutAS
as shown below:Then, you can get the result below: