Database Reference
In-Depth Information
2.
Create the server using CREATE SERVER :
postgres=# CREATE SERVER file_svr FOREIGN DATA WRAPPER
file_fdw;
3.
Create a foreign table using CREATE FOREIGN TABLE :
postgres=# CREATE FOREIGN TABLE logfile
(log_id INTEGER,
log_detail TEXT,
log_date date)
SERVER file_svr
OPTIONS (filename, 'log.txt', delimiter ',');
The log.txt ile contains one record per line and every ield is separated by
a comma; in other words, log.txt is a Comma Separated File ( CSF ).
The contents of the log.txt ile are:
$ cat log.txt
1. Unable to open file, 01/12/2014
2. Parsing error , 02/01/2014
3. Initialization failed, 02/01/2014
Selecting the data from a foreign server will show the contents of the log.txt ile:
postgres=# SELECT * FROM logfile;
log_id | log_detail | log_date
--------+-------------------------+------------
1 | Unable to open file | 2014-12-01
2 | Parsing error' | 2014-01-02
3 | Initialization failed | 2014-01-02
(3 rows)
Summary
In this chapter, we learned what a foreign data wrapper is, how to create a foreign
data wrapper and how to use existing foreign data wrappers. We have also learned
postgres_fdw and file_fdw in detail.
In the next chapter, we will learn what an extension is and how to create extensions
and how to use existing extensions.
 
Search WWH ::




Custom Search