-- ========
-- PROTOCOL
-- ========

-- create the database functions
CREATE OR REPLACE FUNCTION read_from_s3() RETURNS integer AS
	'$libdir/gps3ext.so', 's3_import' LANGUAGE C STABLE;

-- declare the protocol name along with in/out funcs
CREATE PROTOCOL s3 (
	readfunc  = read_from_s3
);

-- Check out the catalog table
select * from pg_extprotocol;

drop external table s3example;

create READABLE external table s3example (date text, time text, open float, high float,
       low float, volume int) location('s3://s3-us-west-2.amazonaws.com/metro.pivotal.io/baddata config=/home/gpadmin/work/bootgpdb/data/gpseg0/s3/s3.conf') format 'csv' LOG ERRORS SEGMENT REJECT LIMIT 5;
SELECT count(*) FROM s3example;

-- =======
-- CLEANUP
-- =======
DROP EXTERNAL TABLE s3example;

DROP PROTOCOL s3;
