postgresql从9.1开始增加了外部表访问的功能,这个功能就是数据库直接读取数据库以外的文件,比如csv或者text等类型的文件,暂时
postgresql从9.1开始增加了外部表访问的功能,这个功能就是数据库直接读取数据库以外的文件,比如csv或者text等类型的文件,暂时不支持DML。postgresql有各种插件能直连各种异构DB,如Oracle_fdw,mysql_fdw,file_fdw等,对数据的迁移是很方便的,这是PG的扩展性较强的一个表现。这里介绍foreign data wrapper的file_fdw使用。
相关阅读:
PostgreSQL 9.3物化视图使用
使用 PostgreSQL 数据库日期类型的 4 个提示
PostgreSQL删除表中重复数据行
PostgreSQL缓存详述
Windows平台编译 PostgreSQL
Ubuntu下LAPP(Linux+Apache+PostgreSQL+PHP)环境的配置与安装
一、环境:
OS :CentOS 6.3
DB :PostgreSQL 9.3
二、使用过程
1.创建扩展,因为默认不安装,安装需要手工创建
2.创建外部表服务接口,查看
postgres=# create server pg_file_server foreign data wrapper file_fdw; CREATE SERVER postgres=# \des List of foreign servers Name | Owner | Foreign-data wrapper ----------------+----------+---------------------- pg_file_server | postgres | file_fdw (1 row)3.建立一个外部表,与外部文件结构一致
postgres=# create foreign table tab_area(id int,cname varchar(80),ename varchar(80),create_time varchar(30)) server pg_file_server options(filename '/home/postgres/data1.csv',format 'csv',header on,delimiter ',',null '1'); --后面options里面参数的说明 --filename后面是文件名和绝对路径 --format是格式,csv是逗号分隔,text表示是tab分隔的方式 --delimiter是分隔符 --header表示第一行数据是否需要 --null表示空数据的转化处理,例子中字段1将转化为null4.上传外部文件
[postgres@kenyon ~]$ more data1.csv ?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-125.查询
postgres=# select * from tab_area; id | cname | ename | create_time ----+-------+----------+------------- | 浙江 | 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)6.查看外部表
postgres=# \d+ tab_area Foreign table "public.tab_area" Column | Type | Modifiers | FDW Options | Storage | Stats target | Description -------------+-----------------------+-----------+-------------+----------+--------------+------------- id | integer | | | plain | | cname | character varying(80) | | | extended | | ename | character varying(80) | | | extended | | create_time | character varying(10) | | | extended | | Server: pg_file_server FDW Options: (filename '/home/postgres/data1.csv', format 'csv', delimiter ',', header 'true', "null" '1') Has OIDs: no接下来请看第2页精彩内容:
PostgreSQL 的详细介绍:请点这里
PostgreSQL 的下载地址:请点这里

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

TostorestringsefficientlyinMySQL,choosetherightdatatypebasedonyourneeds:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseTEXTforlong-formtextcontent.4)UseBLOBforbinarydatalikeimages.Considerstorageov

When selecting MySQL's BLOB and TEXT data types, BLOB is suitable for storing binary data, and TEXT is suitable for storing text data. 1) BLOB is suitable for binary data such as pictures and audio, 2) TEXT is suitable for text data such as articles and comments. When choosing, data properties and performance optimization must be considered.

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQLstringdatatypesshouldbechosenbasedondatacharacteristicsandusecases:1)UseCHARforfixed-lengthstringslikecountrycodes.2)UseVARCHARforvariable-lengthstringslikenames.3)UseBINARYorVARBINARYforbinarydatalikecryptographickeys.4)UseBLOBorTEXTforlargeuns


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools
