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,
^
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
----+-----+------------+----+-----+------------
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;
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,
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;