\c postgres <%= @pg_role %> CREATE EXTENSION treasuredata_fdw; CREATE SERVER treasuredata_server FOREIGN DATA WRAPPER treasuredata_fdw; CREATE FOREIGN TABLE td_www_access ( time integer, code integer, size integer, method varchar ) SERVER treasuredata_server OPTIONS ( apikey '<%= @apikey %>', database 'sample_datasets', query_engine '<%= @query_engine %>', table 'www_access' ); SELECT * FROM td_www_access ORDER BY TIME LIMIT 5; SELECT COUNT(1) FROM td_www_access; SELECT COUNT(1) FROM td_www_access WHERE time < 1412320911; SELECT COUNT(1) FROM td_www_access WHERE SUBSTR(method, 1, 3) = 'POS'; SELECT COUNT(1) FROM td_www_access WHERE method LIKE '%ET' AND code = 200; SELECT COUNT(1) FROM td_www_access WHERE method NOT LIKE '%ET' AND code NOT IN (404); SELECT COUNT(1) FROM td_www_access WHERE time in (SELECT MIN(time) FROM td_www_access); -- For https://github.com/komamitsu/treasuredata_fdw/issues/23 SELECT COUNT(1) FROM (SELECT * FROM td_www_access LIMIT 1) x WHERE size > 0; CREATE FOREIGN TABLE td_summary_in_www_access ( code integer, method varchar, count integer ) SERVER treasuredata_server OPTIONS ( apikey '<%= @apikey %>', database 'sample_datasets', query_engine '<%= @query_engine %>', query 'SELECT code, method, COUNT(1) as count FROM www_access GROUP BY code, method' ); SELECT * FROM td_summary_in_www_access ORDER BY code, method; SELECT method, code FROM td_summary_in_www_access ORDER BY code, method; CREATE FOREIGN TABLE td_www_access_dst ( time integer, code integer, size integer, method varchar ) SERVER treasuredata_server OPTIONS ( apikey '<%= @apikey %>', database 'treasuredata_fdw', query_engine '<%= @query_engine %>', table 'www_access_dst', import_file_size '50000', atomic_import 'true' ); INSERT INTO td_www_access_dst SELECT * FROM td_www_access; CREATE FOREIGN TABLE td_array_test ( str_array text[], int_array integer[], long_array bigint[], float_array float[], double_array float[], str_array_array text[][], int_array_array integer[][], long_array_array bigint[][], float_array_array float[][], double_array_array float[][] ) SERVER treasuredata_server OPTIONS ( apikey '<%= @apikey %>', database 'treasuredata_fdw', query_engine '<%= @query_engine %>', table 'array_test' ); SELECT * FROM td_array_test; DROP FOREIGN TABLE td_www_access_dst; DROP FOREIGN TABLE td_summary_in_www_access; DROP FOREIGN TABLE td_www_access; DROP FOREIGN TABLE td_array_test; DROP SERVER treasuredata_server; DROP EXTENSION treasuredata_fdw CASCADE;