手机版
你好,游客 登录 注册
背景:
阅读新闻

PostgreSQL的外部表使用

[日期:2013-10-03] 来源:oschina.net  作者:Kenyon [字体:大 中 小]

7.与实际普通表的结合

postgres=# create table tab_act_area as select * from tab_area;
SELECT 7
postgres=# insert into tab_act_area select * from tab_area where id>2;
INSERT 0 5
postgres=# \d+
                              List of relations
 Schema |     Name     |     Type      |  Owner   |    Size    | Description 
--------+--------------+---------------+----------+------------+-------------
 public | empsalary    | table         | postgres | 16 kB      | 
 public | tab_act_area | table         | postgres | 8192 bytes | 
 public | tab_area     | foreign table | postgres | 0 bytes    | 
 public | test         | table         | postgres | 5096 kB    | 
(4 rows)

8.修改外部表

postgres=# alter foreign table tab_area options(set null '^null*');
ALTER FOREIGN TABLE
postgres=# select * from tab_area;
 id | cname |  ename   | create_time 
----+-------+----------+-------------
  1 | 浙江  | zhejiang | 2013-01-01
  2 | 杭州  | hangzhou | 2013-01-02
  3 | 北京  | beijing  | 2012-09-12
  4 | 默认  |          | 2013-09-10
  5 | 四川  | sichuan  | 2012-12-12
  6 |       | nanjing  | 
  7 | 甘肃  |          | 1998-12-12
(7 rows)

其他语法和普通表类似,除了option的三个选项(drop、add和set) ,具体参考:

http://www.postgresql.org/docs/9.3/static/sql-alterforeigntable.html

9.工具的使用


三总结:
1.外部表实际不存储数据,只是一张表结构;
2.9.2版本比9.1版本多了option的选择,9.3又多了collate一些排序的补充,功能进一步完善,现在已有约束、default普通表的应有功能;
3.实用性,对定期的数据抽取但无需入库检查是很方便的,既减少了数据存储,像基于postgresql的greenplum的数据导入导出就非常实用

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款