Add some regression test cases to contrib/postgresql_fdw.
authorShigeru Hanada <[email protected]>
Thu, 14 Oct 2010 09:00:35 +0000 (18:00 +0900)
committerShigeru Hanada <[email protected]>
Thu, 14 Oct 2010 09:00:35 +0000 (18:00 +0900)
contrib/postgresql_fdw/expected/postgresql_fdw.out
contrib/postgresql_fdw/sql/postgresql_fdw.sql

index 3cfa2f8bf1ef9351cb8fe783bf0475c2d85fc2e2..409d465d0a5a167526b3f1730921a9703463eb78 100644 (file)
@@ -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;
index 43db5ddd09dba279e6e4fff1789a2da48e0a853c..8c58311808f51444edb986e4190e0c0a56a3e29d 100644 (file)
@@ -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;