1 AT_BANNER([GET DATA /TYPE=PSQL])
4 [AT_SKIP_IF([test "$PSQL_SUPPORT" = no])
11 socket_dir=`mktemp -d`
14 AT_CHECK([initdb -A trust], [0], [ignore])
15 AT_CHECK([pg_ctl start -w -o "-k $socket_dir -h ''"], [0], [ignore])
17 AT_CHECK([createdb -h "$socket_dir" -p $PG_PORT $PG_DBASE],
18 [0], [ignore], [ignore])
19 AT_DATA([populate.sql],
20 [CREATE TABLE empty (a int, b date, c numeric(23, 4));
22 -- a largeish table to check big queries work ok.
23 CREATE TABLE large (x int);
24 INSERT INTO large (select * from generate_series(1, 1000));
34 numeric numeric(50,6) ,
45 timestamptz timestamptz ,
50 INSERT INTO thing VALUES (
67 'January 8 04:05:06 1999',
68 'January 8 04:05:06 1999 PST',
73 INSERT INTO thing VALUES (
96 INSERT INTO thing VALUES (
113 '10-Jan-1963 23:58:00',
114 '10-Jan-1963 23:58:00 CET',
115 '2 year 1 month 12 days 1 hours 3 minutes 4 seconds',
119 AT_CHECK([psql -h "$socket_dir" -p $PG_PORT $PG_DBASE < populate.sql],
122 m4_define([CLEANUP_PSQL], [pg_ctl stop -W -o "-k $socket_dir -h ''"])
124 AT_SETUP([GET DATA /TYPE=PSQL])
127 dnl Test with an ordinary query.
128 AT_CHECK([cat > ordinary-query.sps <<EOF
130 /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
132 /SQL="select * from thing".
139 AT_CHECK([pspp -o pspp.csv ordinary-query.sps])
140 AT_CHECK([cat pspp.csv], [0], [dnl
141 Variable,Description,,Position
144 ,Display Alignment: Right,,
146 bytea,Format: AHEX2,,2
148 ,Display Alignment: Left,,
152 ,Display Alignment: Left,,
156 ,Display Alignment: Right,,
160 ,Display Alignment: Right,,
164 ,Display Alignment: Right,,
166 numeric,Format: E40.6,,7
168 ,Display Alignment: Right,,
172 ,Display Alignment: Left,,
176 ,Display Alignment: Right,,
178 float4,Format: F8.2,,10
180 ,Display Alignment: Right,,
182 float8,Format: F8.2,,11
184 ,Display Alignment: Right,,
186 money,Format: DOLLAR8.2,,12
188 ,Display Alignment: Right,,
190 pbchar,Format: A8,,13
192 ,Display Alignment: Left,,
194 varchar,Format: A8,,14
196 ,Display Alignment: Left,,
198 date,Format: DATE11,,15
200 ,Display Alignment: Right,,
202 time,Format: TIME11.0,,16
204 ,Display Alignment: Right,,
206 timestamp,Format: DATETIME22.0,,17
208 ,Display Alignment: Right,,
210 timestamptz,Format: DATETIME22.0,,18
212 ,Display Alignment: Right,,
214 interval,Format: DTIME13.0,,19
216 ,Display Alignment: Right,,
218 interval_months,Format: F3.0,,20
220 ,Display Alignment: Right,,
222 timetz,Format: TIME11.0,,21
224 ,Display Alignment: Right,,
226 timetz_zone,Format: F8.2,,22
228 ,Display Alignment: Right,,
232 bool,bytea,char,int8,int2,int4,numeric,text,oid,float4,float8,money,pbchar,varchar,date,time,timestamp,timestamptz,interval,interval_months,timetz,timetz_zone
233 .00,30,a ,.00,.00,.00,-2.560980E+002,this-long-text ,.00,.00,.00,$.01,a ,A ,01-JAN-2000,0:00:00,08-JAN-1999 04:05:06,08-JAN-1999 12:05:06,0 00:01:00,0,10:09:00,4.00
234 . ,20,,. ,. ,. ,. ,,. ,. ,. ,. ,,,.,.,.,.,.,.,.,. @&t@
235 1.00,31,b ,1.00,1.00,1.00,6.553500E+004,that-long-text ,.00,1.00,1.00,$1.23,b ,B ,10-JAN-1963,1:05:02,10-JAN-1963 23:58:00,10-JAN-1963 22:58:00,12 01:03:04,25,1:05:02,-7.00
238 dnl Test query with empty result set.
239 AT_CHECK([cat > empty-result.sps <<EOF
241 /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
243 /SQL="select * from empty".
250 AT_CHECK([pspp -o pspp.csv empty-result.sps])
251 AT_CHECK([cat pspp.csv], [0], [dnl
252 Variable,Description,,Position
255 ,Display Alignment: Right,,
259 ,Display Alignment: Right,,
263 ,Display Alignment: Right,,
267 dnl Test query with large result set.
268 AT_CHECK([cat > large-result.sps <<EOF
270 /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
272 /SQL="select * from large".
275 COMPUTE diff = x - lag (x).
278 SELECT IF (diff <> 1).
292 AT_CHECK([pspp -o pspp.csv large-result.sps])
293 AT_CHECK([cat pspp.csv], [0], [dnl
313 dnl Check for a bug caused by having string variables in the database,
314 dnl all of which are null.
315 AT_DATA([all-null-string.sql],
316 [-- a table which has a text field containing only null, or zero
319 CREATE TABLE foo (int4 int4, text text);
321 INSERT INTO foo VALUES ('12', '');
323 INSERT INTO foo VALUES (null, '');
325 AT_CHECK([psql -h "$socket_dir" -p $PG_PORT $PG_DBASE < all-null-string.sql],
327 AT_CAPTURE_FILE([get-data.sps])
328 AT_CHECK([cat > get-data.sps <<EOF
330 /CONNECT="host=$socket_dir port=$PGPORT dbname=$PG_DBASE"
332 /SQL="select * from foo".
339 AT_CHECK([pspp -o pspp.csv get-data.sps])
340 AT_CAPTURE_FILE([pspp.csv])