Postgresql - Foreign data wrappers - file wrappers

file_fdw,可以访问服务器的文件系统的数据,或者执行程序在服务器上,并且读取输出。
数据文件或程序输出必须以可从副本读取的格式。对数据文件的访问是只读的。
环境:
CentOS 7
PG 10.4

准备:
1. 外部表文件
[root@dbwtest03bc data]# cat ft_dir/ft_test01.csv
1,aaa,aaa

2. 文件及文件夹权限
chown -R postgres:postgres ft_dir

创建外部表:
1. create extension
CREATE EXTENSION file_fdw;
mytest=# create extension file_fdw ;
CREATE EXTENSION

2. create a foreign server:
mytest=# CREATE SERVER ft_test01 FOREIGN DATA WRAPPER file_fdw;
CREATE SERVER

3. 创建外部表
mytest=# CREATE FOREIGN TABLE ft_test01 (
mytest(# id int,
mytest(# col1 text,
mytest(# col2 text
mytest(# ) SERVER ft_test01
mytest-# OPTIONS ( filename '/data/ft_dir/ft_test01.csv', format 'csv' );
CREATE FOREIGN TABLE

4. 查看数据
mytest=# select * from ft_test01 ;
id | col1 | col2
----+------+------
1 | aaa | aaa
(1 row)

5. 外部表只读,无法插入,更新,删除
mytest=# update ft_test01 set col1 = 'aaa' , col2 = 'bbb' where id =1 ;
ERROR: cannot update foreign table "ft_test01"
mytest=# insert into ft_test01 values (2,'bbb','ccc');
ERROR: cannot insert into foreign table "ft_test01"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值