加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql 外部表简单测试

发布时间:2020-12-13 17:34:36 所属栏目:百科 来源:网络整理
导读:postgresql 外部表测试 系统 debian-6.0.4 数据库 postgresql-9.3.0 ######################################################################################### 创建扩展,因为默认不安装,安装需要手工创建 psql (9.3.0) Type "help" for help. postgre

postgresql 外部表测试

系统 debian-6.0.4

数据库 postgresql-9.3.0

#########################################################################################

创建扩展,因为默认不安装,安装需要手工创建

psql (9.3.0)

Type "help" for help.


postgres=# CREATE EXTENSION file_fdw;

CREATE EXTENSION

postgres=# dx

List of installed extensions

Name | Version | Schema | Description

----------+---------+------------+--------------------------------------------------------------

dblink | 1.1 | public | connect to other PostgreSQL databases from within a database

file_fdw | 1.0 | public | foreign-data wrapper for flat file access

plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language

(3 rows)

#########################################################################################

创建外部表服务接口,查看

create foreign table tab_x1(ISBN varchar(80),bookname varchar(1000),printing varchar(80),publicationdate varchar(80),price numeric(15,5),discount numeric(15,stock int,location varchar(80),classes varchar(30),remarks varchar(30)) server pg_file_server options(filename '/var/lib/postgresql/9.3/x1.csv',format 'csv',header 'true',delimiter ',',null '1');

--后面options里面参数的说明

--filename后面是文件名和绝对路径

--format是格式,csv是逗号分隔,text表示是tab分隔的方式

--delimiter是分隔符

--header表示第一行数据是否需要

--null表示空数据的转化处理,例子中字段1将转化为null

#########################################################################################

上传外部文件

上传外部文件到相应目录如本例中的/var/lib/postgresql/9.3/x1.csv

#########################################################################################

查询

postgres=# select * from tab_x1 limit 10;

isbn | bookname | printing | publicationdate | price | discount | stock | location | classes | remarks

----------------+------------------------+----------+-----------------+----------+----------+-------+----------+---------+---------

9787539138855 | 十一月,枫火燎原 | 21世纪 | 2007年11月 | 9.80000 | 0.13000 | 1 | 1007 | I | 特价

9787533654962 | 熟女日记2 | 安徽教育 | 2010年6月 | 23.00000 | 0.13000 | 43 | 1204 | I | 特价

9787533654979 | 一个中国人在中国的遭遇 | 安徽教育 | 2010年3月 | 25.00000 | 0.13000 | 128 | 3602 | I | 特价

9787533728403 | 水榭 | 安徽科技 | 2004年2月 | 60.00000 | 0.13000 | 2 | 307 | T | 特价

9787533728915 | 建筑与装饰工程造价问答 | 安徽科技 | 2005年1月 | 32.80000 | 0.13000 | 2 | 3101 | T | 特价

9787533732257 | 西藏旅游摄影指南 | 安徽科技 | 2005年5月 | 8.00000 | 0.13000 | 1 | 2007 | K | 特价

9787533733322 | 异案良方 | 安徽科技 | 2005年9月 | 38.00000 | 0.13000 | 2 | 3005 | R | 特价

9787533733384 | 复式住宅装潢 | 安徽科技 | 2005年10月 | 32.00000 | 0.13000 | 1 | 2707 | T | 特价

9787563708253 | 旅游教育出版社 | 安徽科技 | 2002年10月 | 12.90000 | 0.13000 | 2 | 507 | K | 特价

9787539808307 | 环境艺术设计 | 安徽美术 | 2000年9月 | 18.00000 | 0.13000 | 1 | 3007 | T | 特价

(10 rows)

#########################################################################################

查看外部表

postgres=# d+ tab_x1

Foreign table "public.tab_x1"

Column | Type | Modifiers | FDW Options | Storage | Stats target | Description

-----------------+-------------------------+-----------+-------------+----------+--------------+-------------

isbn | character varying(80) | | | extended | |

bookname | character varying(1000) | | | extended | |

printing | character varying(80) | | | extended | |

publicationdate | character varying(80) | | | extended | |

price | numeric(15,5) | | | main | |

discount | numeric(15,5) | | | main | |

stock | integer | | | plain | |

location | character varying(80) | | | extended | |

classes | character varying(30) | | | extended | |

remarks | character varying(30) | | | extended | |

Server: pg_file_server

FDW Options: (filename '/var/lib/postgresql/9.3/x1.csv',"null" '1')

Has OIDs: no

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读