@@ -6,39 +6,34 @@ require postgres_scanner
66
77require-env POSTGRES_TEST_DATABASE_AVAILABLE
88
9- # e.g. export SPATIAL_EXTENSION='~/Programs/duckdb-spatial/build/debug/extension/spatial/spatial.duckdb_extension'
10- require-env SPATIAL_EXTENSION
11-
129statement ok
1310PRAGMA enable_verification
1411
1512statement ok
1613ATTACH 'dbname=postgres' AS s (TYPE POSTGRES);
1714
18- # make sure PostGIS is installed
15+ # Cleanup
1916statement ok
20- SELECT * FROM postgres_query(s, 'SELECT PostGIS_Version()')
17+ DROP TABLE IF EXISTS s.my_points;
2118
22- # spatial not loaded yet
23- statement error
24- CREATE OR REPLACE TABLE s.my_points(geom GEOMETRY);
25- ----
26- spatial
19+ statement ok
20+ DROP TABLE if EXISTS s.t1_copy;
2721
22+ # make sure PostGIS is installed
2823statement ok
29- LOAD '${SPATIAL_EXTENSION}'
24+ SELECT * FROM postgres_query(s, 'SELECT PostGIS_Version()')
3025
3126# create a table
3227statement ok
3328CREATE OR REPLACE TABLE s.my_points(geom GEOMETRY);
3429
3530# insert data
3631statement ok
37- INSERT INTO s.my_points VALUES (ST_Point(1,1) );
32+ INSERT INTO s.my_points VALUES ('POINT (1 1)'::GEOMETRY );
3833
3934# try binary copy
4035query I
41- SELECT geom::VARCHAR FROM s.my_points;
36+ SELECT geom FROM s.my_points;
4237----
4338POINT (1 1)
4439
@@ -47,14 +42,32 @@ statement ok
4742SET pg_use_binary_copy=false;
4843
4944statement ok
50- INSERT INTO s.my_points VALUES (ST_Point(2,2) );
45+ INSERT INTO s.my_points VALUES ('POINT (2 2)'::GEOMETRY );
5146
5247query I
5348SELECT geom::VARCHAR FROM s.my_points;
5449----
5550POINT (1 1)
5651POINT (2 2)
5752
53+ query I
54+ SELECT geom from s.my_points;
55+ ----
56+ POINT (1 1)
57+ POINT (2 2)
58+
59+ statement ok
60+ set pg_use_text_protocol=true;
61+
62+ query I
63+ SELECT geom from s.my_points;
64+ ----
65+ POINT (1 1)
66+ POINT (2 2)
67+
68+ statement ok
69+ set pg_use_text_protocol=false
70+
5871# make sure Postgres itself can read the values
5972query I
6073SELECT * FROM postgres_query(s, 'SELECT ST_AsText(geom) FROM my_points')
@@ -77,10 +90,42 @@ POINT (2 2)
7790
7891# update
7992statement ok
80- UPDATE s.my_points SET geom=ST_Point(ST_X(geom::GEOMETRY) + 10, ST_Y(geom ::GEOMETRY) + 10)
93+ UPDATE s.my_points SET geom='LINESTRING (0 0, 1 1)' ::GEOMETRY
8194
8295query I
8396SELECT geom::VARCHAR FROM s.my_points;
8497----
85- POINT (11 11)
86- POINT (12 12)
98+ LINESTRING (0 0, 1 1)
99+ LINESTRING (0 0, 1 1)
100+
101+ # Also test COPY to
102+ statement ok
103+ CREATE table t1 (g GEOMETRY);
104+
105+ statement ok
106+ CREATE table s.t1_copy (g GEOMETRY);
107+
108+ statement ok
109+ insert into t1 select geom from s.my_points;
110+
111+ query I
112+ select * from t1;
113+ ----
114+ LINESTRING (0 0, 1 1)
115+ LINESTRING (0 0, 1 1)
116+
117+ statement ok
118+ insert into s.t1_copy select g from t1;
119+
120+ query I
121+ SELECT * FROM postgres_query(s, 'SELECT ST_AsText(g) FROM t1_copy')
122+ ----
123+ LINESTRING(0 0,1 1)
124+ LINESTRING(0 0,1 1)
125+
126+ # Cleanup
127+ statement ok
128+ DROP TABLE IF EXISTS s.my_points;
129+
130+ statement ok
131+ DROP TABLE if EXISTS s.t1_copy;
0 commit comments