Skip to content

Commit 7c5d0ae

Browse files
committed
Add contrib/file_fdw foreign-data wrapper for reading files via COPY.
This is both very useful in its own right, and an important test case for the core FDW support. This commit includes a small refactoring of copy.c to expose its option checking code as a separately callable function. The original patch submission duplicated hundreds of lines of that code, which seemed pretty unmaintainable. Shigeru Hanada, reviewed by Itagaki Takahiro and Tom Lane
1 parent bb74240 commit 7c5d0ae

File tree

19 files changed

+1171
-55
lines changed

19 files changed

+1171
-55
lines changed

contrib/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ SUBDIRS = \
1818
dict_xsyn \
1919
dummy_seclabel \
2020
earthdistance \
21+
file_fdw \
2122
fuzzystrmatch \
2223
hstore \
2324
intagg \

contrib/README

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ earthdistance -
7373
Functions for computing distances between two points on Earth
7474
by Bruno Wolff III <[email protected]> and Hal Snyder <[email protected]>
7575

76+
file_fdw
77+
Foreign-data wrapper for server-side CSV/TEXT files
78+
by Shigeru Hanada <[email protected]>
79+
7680
fuzzystrmatch -
7781
Levenshtein, metaphone, and soundex fuzzy string matching
7882
by Joe Conway <[email protected]> and Joel Burton <[email protected]>

contrib/file_fdw/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated subdirectories
2+
/results/

contrib/file_fdw/Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# contrib/file_fdw/Makefile
2+
3+
MODULES = file_fdw
4+
5+
EXTENSION = file_fdw
6+
DATA = file_fdw--1.0.sql
7+
8+
REGRESS = file_fdw
9+
10+
EXTRA_CLEAN = sql/file_fdw.sql expected/file_fdw.out
11+
12+
ifdef USE_PGXS
13+
PG_CONFIG = pg_config
14+
PGXS := $(shell $(PG_CONFIG) --pgxs)
15+
include $(PGXS)
16+
else
17+
subdir = contrib/file_fdw
18+
top_builddir = ../..
19+
include $(top_builddir)/src/Makefile.global
20+
include $(top_srcdir)/contrib/contrib-global.mk
21+
endif

contrib/file_fdw/data/agg.bad

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
56;@7.8@
2+
100;@99.097@
3+
0;@aaa@
4+
42;@324.78@

contrib/file_fdw/data/agg.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
56;@7.8@
2+
100;@99.097@
3+
0;@0.09561@
4+
42;@324.78@

contrib/file_fdw/data/agg.data

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
56 7.8
2+
100 99.097
3+
0 0.09561
4+
42 324.78

contrib/file_fdw/expected/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/file_fdw.out

contrib/file_fdw/file_fdw--1.0.sql

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* contrib/file_fdw/file_fdw--1.0.sql */
2+
3+
CREATE FUNCTION file_fdw_handler()
4+
RETURNS fdw_handler
5+
AS 'MODULE_PATHNAME'
6+
LANGUAGE C STRICT;
7+
8+
CREATE FUNCTION file_fdw_validator(text[], oid)
9+
RETURNS void
10+
AS 'MODULE_PATHNAME'
11+
LANGUAGE C STRICT;
12+
13+
CREATE FOREIGN DATA WRAPPER file_fdw
14+
HANDLER file_fdw_handler
15+
VALIDATOR file_fdw_validator;

0 commit comments

Comments
 (0)