From: Shigeru Hanada Date: Thu, 14 Oct 2010 09:00:35 +0000 (+0900) Subject: Add some regression test cases to contrib/postgresql_fdw. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=35a496048719ababd9180ac5391575489aefbf6b;p=users%2Fhanada%2Fpostgres.git Add some regression test cases to contrib/postgresql_fdw. --- diff --git a/contrib/postgresql_fdw/expected/postgresql_fdw.out b/contrib/postgresql_fdw/expected/postgresql_fdw.out index 3cfa2f8bf1..409d465d0a 100644 --- a/contrib/postgresql_fdw/expected/postgresql_fdw.out +++ b/contrib/postgresql_fdw/expected/postgresql_fdw.out @@ -24,6 +24,12 @@ CREATE TABLE t1( c3 date ); COPY t1 FROM stdin; +CREATE TABLE t2( + c1 integer, + c2 text, + c3 date +); +COPY t2 FROM stdin; CREATE FOREIGN TABLE ft1 ( c1 integer, c2 text, @@ -55,24 +61,23 @@ LINE 1: SELECT c1, c2, c3 FROM public.invalid ft2 ^ HINT: SELECT c1, c2, c3 FROM public.invalid ft2 -ALTER FOREIGN TABLE ft2 OPTIONS (SET relname 't1'); +ALTER FOREIGN TABLE ft2 OPTIONS (SET relname 't2'); SELECT * FROM ft2 ORDER BY c1; c1 | c2 | c3 ----+-----+------------ 1 | foo | 01-01-1970 - 2 | bar | 01-02-1970 - 3 | buz | 01-03-1970 + 12 | bar | 01-02-1970 + 13 | buz | 01-03-1970 (3 rows) --- query using join +-- join two foreign tables SELECT * FROM ft1 JOIN ft2 ON (ft1.c1 = ft2.c1) ORDER BY ft1.c1; c1 | c2 | c3 | c1 | c2 | c3 ----+-----+------------+----+-----+------------ 1 | foo | 01-01-1970 | 1 | foo | 01-01-1970 - 2 | bar | 01-02-1970 | 2 | bar | 01-02-1970 - 3 | buz | 01-03-1970 | 3 | buz | 01-03-1970 -(3 rows) +(1 row) +-- join itself SELECT * FROM ft1 t1 JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1; c1 | c2 | c3 | c1 | c2 | c3 ----+-----+------------+----+-----+------------ @@ -81,6 +86,32 @@ SELECT * FROM ft1 t1 JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1; 3 | buz | 01-03-1970 | 3 | buz | 01-03-1970 (3 rows) +-- outer join +SELECT * FROM ft1 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY 1,2,3,4,5,6; + c1 | c2 | c3 | c1 | c2 | c3 +----+-----+------------+----+-----+------------ + 1 | foo | 01-01-1970 | 1 | foo | 01-01-1970 + 2 | bar | 01-02-1970 | | | + 3 | buz | 01-03-1970 | | | +(3 rows) + +-- WHERE clause push-down +set client_min_messages = debug1; +SELECT * FROM ft1 WHERE c1 = 1 AND c2 = lower('FOO') AND c3 < now(); +DEBUG: deparsed SQL is "SELECT c1, c2, c3 FROM public.t1 ft1 WHERE ((c1 = 1) AND (c2 = 'foo'::text))" + c1 | c2 | c3 +----+-----+------------ + 1 | foo | 01-01-1970 +(1 row) + +reset client_min_messages; -- clean up DROP FOREIGN DATA WRAPPER postgresql_fdw CASCADE; +NOTICE: drop cascades to 6 other objects +DETAIL: drop cascades to server loopback1 +drop cascades to user mapping for public +drop cascades to foreign table ft1 +drop cascades to server loopback2 +drop cascades to user mapping for public +drop cascades to foreign table ft2 DROP TABLE t1 CASCADE; diff --git a/contrib/postgresql_fdw/sql/postgresql_fdw.sql b/contrib/postgresql_fdw/sql/postgresql_fdw.sql index 43db5ddd09..8c58311808 100644 --- a/contrib/postgresql_fdw/sql/postgresql_fdw.sql +++ b/contrib/postgresql_fdw/sql/postgresql_fdw.sql @@ -38,6 +38,18 @@ COPY t1 FROM stdin; 3 buz 1970-01-03 \. +CREATE TABLE t2( + c1 integer, + c2 text, + c3 date +); + +COPY t2 FROM stdin; +1 foo 1970-01-01 +12 bar 1970-01-02 +13 buz 1970-01-03 +\. + CREATE FOREIGN TABLE ft1 ( c1 integer, c2 text, @@ -55,12 +67,19 @@ SELECT * FROM ft1 ORDER BY c1; SELECT * FROM ft2 ORDER BY c1; -- ERROR ALTER USER MAPPING FOR PUBLIC SERVER loopback2 OPTIONS (DROP user); SELECT * FROM ft2 ORDER BY c1; -- ERROR -ALTER FOREIGN TABLE ft2 OPTIONS (SET relname 't1'); +ALTER FOREIGN TABLE ft2 OPTIONS (SET relname 't2'); SELECT * FROM ft2 ORDER BY c1; --- query using join +-- join two foreign tables SELECT * FROM ft1 JOIN ft2 ON (ft1.c1 = ft2.c1) ORDER BY ft1.c1; +-- join itself SELECT * FROM ft1 t1 JOIN ft1 t2 ON (t1.c1 = t2.c1) ORDER BY t1.c1; +-- outer join +SELECT * FROM ft1 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) ORDER BY 1,2,3,4,5,6; +-- WHERE clause push-down +set client_min_messages = debug1; +SELECT * FROM ft1 WHERE c1 = 1 AND c2 = lower('FOO') AND c3 < now(); +reset client_min_messages; -- clean up DROP FOREIGN DATA WRAPPER postgresql_fdw CASCADE;