Postgres-从SELECT创建表 [英] Postgres - CREATE TABLE FROM SELECT

查看:162
本文介绍了Postgres-从SELECT创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,一个表包含大量ID和有关这些ID的信息。

I have two tables, one contains a large list of IDs and Info regarding those ids.

我有第二个表 Graph 仅有两列,每列多次包含上述ID号。我想通过选择仅出现在图形中的那些ID并创建一个新的修剪我的 Info 表的大小较小的信息表。有一个简单的方法吗?

I have a second table Graph which just has two columns, each column contains the aforementioned id numbers, multiple times. I want to trim the size of my Info table by selecting only those ids that appear in my graph and creating a new smaller Info table. Is there a simple way of doing this?

CREATE TABLE FROM SELECT? 

谢谢!

推荐答案

这很容易:

create table new_table
as 
select t1.col1, t2.col2
from some_table t1
   join t2 on t1.id = t2.some_id;

您可以为此使用任何select语句。新表的列名由查询中使用的列别名定义。

You can use any select statement for that. The column names of the new table are defined by the column aliases used in th query.

手册中的更多详细信息: http://www.postgresql.org/docs/current/static/sql-createtableas.html

More details in the manual: http://www.postgresql.org/docs/current/static/sql-createtableas.html

这篇关于Postgres-从SELECT创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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