PostgreSQL SELECT INTO和INSERT INTO SELECT 表复制语句

一、INSERT INTO FROM语句
    语句形式为:INSERT INTO table2(field1,field2,…) SELECT value1,value2,… from table1 要求目标表table2必须存在。

    1、创建临时表:

        create temporary table tmp_idfa_fm (id bigserial primary key,idfa text, num int);

    2、插入数据:

        insert into tmp_idfa_fm (idfa, num) select idfa, count(idfa) as ct from nlogs where idfa!='' and sendtime>='2015-09-01 00:00:00' and sendtime<'2015-12-01 00:00:00' group by idfa order by ct desc ;

 

二、SELECT INTO FROM语句

    语句形式为:SELECT vale1, value2 into table2 FROM table1

    要求目标表table2不存在,因为在插入时会自动创建表table2,并将table1中指定字段数据复制到table2中。

    查询语句:

        select idfa, recvtime into tmp_tb1 from nlogs where recvtime>='2015-09-01 00:00:00' and recvtime<'2015-09-03 00:00:00';

 

 

转载于:https://my.oschina.net/u/3625745/blog/3000257

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值