select cs_cast(Volume, 'float4') from Quote_get('IBM'); cs_cast ------------------------------ float4:{100,200,300,400,500} (1 row) select cs_iif(Volume>10, Open, Close) from Quote_get('IBM'); cs_iif ----------------------------------- float4:{10.2,20.2,30.5,40.5,50.2} (1 row) select cs_if(Open Close, Day) from Quote_get('IBM'); cs_filter ------------------------------ date:{11-04-2013,11-05-2013} (1 row) select Quote_project(q.*, cs_filter_pos(High > Low*1.01)) from Quote_get('IBM', null, date('05-Nov-2013')) q; quote_project -------------------------------------- (IBM,11-01-2013,10.2,11,10,10.5,100) (IBM,11-04-2013,30.5,31,30,30.2,300) (IBM,11-05-2013,40.5,41,40,40.2,400) (3 rows) select Quote_project(q.*, cs_filter_first_pos(High > Low*1.01, 3)) from Quote_get('IBM') q; quote_project -------------------------------------- (IBM,11-01-2013,10.2,11,10,10.5,100) (IBM,11-04-2013,30.5,31,30,30.2,300) (IBM,11-05-2013,40.5,41,40,40.2,400) (3 rows) select cs_unique(Volume/200) from Quote_get('IBM'); cs_unique -------------- int4:{0,1,2} (1 row) select cs_reverse(Day) from Quote_get('IBM'); cs_reverse --------------------------------------------------------------- date:{11-06-2013,11-05-2013,11-04-2013,11-02-2013,11-01-2013} (1 row) select cs_diff(Close) from Quote_get('IBM'); cs_diff --------------------------- float4:{0,9.7,10,10,10.3} (1 row) select cs_trend(Close) from Quote_get('IBM'); cs_trend ------------------ char:{0,1,1,1,1} (1 row) select cs_project(q.*) from (select Day,cs_maxof(Open,Close) from Quote_get('IBM', date('02-Nov-2013'))) q; cs_project ------------------- (11-02-2013,20.2) (11-04-2013,30.5) (11-05-2013,40.5) (11-06-2013,50.5) (4 rows) select cs_map(Volume, cs_top_max_pos(Close, 1)) from Quote_get('IBM'); cs_map ------------ int4:{500} (1 row) select cs_union(ibm.Day, abb.Day) from Quote_get('ABB') as abb, Quote_get('IBM') as ibm; cs_union -------------------------------------------------------------------------- date:{11-01-2013,11-02-2013,11-03-2013,11-04-2013,11-05-2013,11-06-2013} (1 row) create function mul2(x float) returns float as $$ begin return x*2; end; $$ language plpgsql strict immutable; select cs_call(Close, 'mul2'::regproc) from Quote_get('IBM'); cs_call -------------------------------------------------------------------- float8:{21,40.4000015258789,60.4000015258789,80.4000015258789,101} (1 row) select cs_call(Close, 'sin'::regproc) from Quote_get('IBM'); cs_call ----------------------------------------------------------------------------------------------------- float8:{-0.87969575997167,0.975820684524937,-0.937691475202754,0.597759755275722,0.232373761655485} (1 row) select cs_to_int4_array('int4:{1,2,3,4,5}'); cs_to_int4_array ------------------ {1,2,3,4,5} (1 row) select cs_to_float4_array('int4:{1,2,3,4,5}'); ERROR: Type of sequence element int4 doesn't match with function cs_to_float4_array return type select cs_sum(cs_from_array(array[1,2,3,4,5])); cs_sum -------- 15 (1 row) select cs_to_bpchar_array('bpchar10:{Hello,World,!}'); cs_to_bpchar_array -------------------- {Hello,World,!} (1 row) select cs_from_array(array['Hello','World','!'], 10); cs_from_array -------------------------- bpchar10:{Hello,World,!} (1 row) select cs_parse('{100.99,99.01,"$1,000,000"}', 'money'); cs_parse ---------------------------------------- money:{$100.99,$99.01,"$1,000,000.00"} (1 row) select cs_cast(cs_parse('{100.99,99.01,1000000}', 'money') * 2, 'money'); cs_cast ----------------------------------------- money:{$201.98,$198.02,"$2,000,000.00"} (1 row) select cs_cast('float4:{100.99,99.01,1000000}', 'money'); cs_cast ---------------------------------------- money:{$100.99,$99.01,"$1,000,000.00"} (1 row) select cs_cast('money:{100.99,99.01,"1,000,000"}', 'float8'); cs_cast ------------------------------- float8:{100.99,99.01,1000000} (1 row) select cs_trend('int4:{1,2,3,3,2,2,4,5,6,5,5}'); cs_trend ---------------------------------- char:{0,1,1,1,-1,-1,1,1,1,-1,-1} (1 row)