hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From foy...@apache.org
Subject [5/9] incubator-hawq git commit: HAWQ-149. Add orafce, gp_cancel_query, pgbench and extprotocol to HAWQ
Date Thu, 12 Nov 2015 20:25:22 GMT
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/orafunc-gp.full.sql
----------------------------------------------------------------------
diff --git a/contrib/orafce/orafunc-gp.full.sql b/contrib/orafce/orafunc-gp.full.sql
new file mode 100644
index 0000000..621c3d0
--- /dev/null
+++ b/contrib/orafce/orafunc-gp.full.sql
@@ -0,0 +1,1324 @@
+-- Adjust this setting to control where the objects get created.
+SET search_path = public;
+
+BEGIN;
+
+CREATE FUNCTION pg_catalog.trunc(value date, fmt text)
+RETURNS date
+AS 'MODULE_PATHNAME','ora_date_trunc'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.trunc(date,text) IS 'truncate date according to the specified format';
+
+CREATE FUNCTION pg_catalog.round(value date, fmt text)
+RETURNS date
+AS 'MODULE_PATHNAME','ora_date_round'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.round(date, text) IS 'round dates according to the specified format';
+
+CREATE FUNCTION pg_catalog.next_day(value date, weekday text)
+RETURNS date
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.next_day (date, text) IS 'returns the first weekday that is greather than a date value';
+
+CREATE FUNCTION pg_catalog.next_day(value date, weekday integer)
+RETURNS date
+AS 'MODULE_PATHNAME', 'next_day_by_index'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.next_day (date, integer) IS 'returns the first weekday that is greather than a date value';
+
+CREATE FUNCTION pg_catalog.last_day(value date)
+RETURNS date
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.last_day(date) IS 'returns last day of the month based on a date value';
+
+CREATE FUNCTION pg_catalog.months_between(date1 date, date2 date)
+RETURNS numeric
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.months_between(date, date) IS 'returns the number of months between date1 and date2';
+
+CREATE FUNCTION pg_catalog.add_months(day date, value int)
+RETURNS date
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.add_months(date, int) IS 'returns date plus n months';
+
+CREATE FUNCTION pg_catalog.trunc(value timestamp with time zone, fmt text)
+RETURNS timestamp with time zone
+AS 'MODULE_PATHNAME', 'ora_timestamptz_trunc'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.trunc(timestamp with time zone, text) IS 'truncate date according to the specified format';
+
+CREATE FUNCTION pg_catalog.round(value timestamp with time zone, fmt text)
+RETURNS timestamp with time zone
+AS 'MODULE_PATHNAME','ora_timestamptz_round'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.round(timestamp with time zone, text) IS 'round dates according to the specified format';
+
+CREATE FUNCTION pg_catalog.round(value timestamp with time zone)
+RETURNS timestamp with time zone
+AS $$ SELECT pg_catalog.round($1, 'DDD'); $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.round(timestamp with time zone) IS 'will round dates according to the specified format';
+
+CREATE FUNCTION pg_catalog.round(value date)
+RETURNS date
+AS $$ SELECT $1; $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.round(value date)IS 'will round dates according to the specified format';
+
+CREATE FUNCTION pg_catalog.trunc(value timestamp with time zone)
+RETURNS timestamp with time zone
+AS $$ SELECT pg_catalog.trunc($1, 'DDD'); $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.trunc(timestamp with time zone) IS 'truncate date according to the specified format';
+
+CREATE FUNCTION pg_catalog.trunc(value date)
+RETURNS date
+AS $$ SELECT $1; $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.trunc(date) IS 'truncate date according to the specified format';
+
+CREATE FUNCTION pg_catalog.nlssort(text, text)
+RETURNS bytea
+AS 'MODULE_PATHNAME', 'ora_nlssort'
+LANGUAGE 'C' IMMUTABLE;
+COMMENT ON FUNCTION pg_catalog.nlssort(text, text) IS '';
+
+CREATE FUNCTION pg_catalog.nlssort(text)
+RETURNS bytea
+AS $$ SELECT pg_catalog.nlssort($1, null); $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.nlssort(text)IS '';
+
+CREATE FUNCTION pg_catalog.set_nls_sort(text)
+RETURNS void
+AS 'MODULE_PATHNAME', 'ora_set_nls_sort'
+LANGUAGE 'C' IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.set_nls_sort(text) IS '';
+
+CREATE FUNCTION pg_catalog.instr(str text, patt text, start int, nth int)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr4'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.instr(text, text, int, int) IS 'Search pattern in string';
+
+CREATE FUNCTION pg_catalog.instr(str text, patt text, start int)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr3'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.instr(text, text, int) IS 'Search pattern in string';
+
+CREATE FUNCTION pg_catalog.instr(str text, patt text)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr2'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.instr(text, text) IS 'Search pattern in string';
+
+CREATE FUNCTION pg_catalog.to_char(num int)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_to_char_int4'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.to_char(int) IS 'Convert number to string';
+
+CREATE FUNCTION pg_catalog.to_char(num bigint)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_to_char_int8'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.to_char(bigint) IS 'Convert number to string';
+
+CREATE FUNCTION pg_catalog.to_char(num real)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_to_char_float4'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.to_char(real) IS 'Convert number to string';
+
+CREATE FUNCTION pg_catalog.to_char(num double precision)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_to_char_float8'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.to_char(double precision) IS 'Convert number to string';
+
+CREATE FUNCTION pg_catalog.to_char(num numeric)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_to_char_numeric'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.to_char(numeric) IS 'Convert number to string';
+
+CREATE FUNCTION pg_catalog.to_number(str text)
+RETURNS numeric
+AS 'MODULE_PATHNAME','orafce_to_number'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.to_number(text) IS 'Convert string to number';
+
+CREATE FUNCTION pg_catalog.to_date(str text)
+RETURNS date
+AS $$ SELECT $1::date; $$
+LANGUAGE sql IMMUTABLE STRICT;
+COMMENT ON FUNCTION pg_catalog.to_date(text) IS 'Convert string to date';
+
+CREATE FUNCTION to_multi_byte(str text)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_to_multi_byte'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION to_multi_byte(text) IS 'Convert all single-byte characters to their corresponding multibyte characters';
+
+CREATE FUNCTION bitand(bigint, bigint)
+RETURNS bigint
+AS $$ SELECT $1 & $2; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE FUNCTION sinh(float8)
+RETURNS float8 AS
+$$ SELECT (exp($1) - exp(-$1)) / 2; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE FUNCTION cosh(float8)
+RETURNS float8 AS
+$$ SELECT (exp($1) + exp(-$1)) / 2; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE FUNCTION tanh(float8)
+RETURNS float8 AS
+$$ SELECT sinh($1) / cosh($1); $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE FUNCTION nanvl(float4, float4)
+RETURNS float4 AS
+$$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE FUNCTION nanvl(float8, float8)
+RETURNS float8 AS
+$$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE FUNCTION nanvl(numeric, numeric)
+RETURNS numeric AS
+$$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE FUNCTION dump("any") 
+RETURNS varchar
+AS 'MODULE_PATHNAME', 'orafce_dump'
+LANGUAGE C;
+
+CREATE FUNCTION dump("any", integer) 
+RETURNS varchar
+AS 'MODULE_PATHNAME', 'orafce_dump'
+LANGUAGE C;
+
+CREATE SCHEMA plvstr;
+
+CREATE FUNCTION plvstr.rvrs(str text, start int, _end int)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_rvrs'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plvstr.rvrs(text, int, int) IS 'Reverse string or part of string';
+
+CREATE FUNCTION plvstr.rvrs(str text, start int)
+RETURNS text
+AS $$ SELECT plvstr.rvrs($1,$2,NULL);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rvrs(text, int) IS 'Reverse string or part of string';
+
+CREATE FUNCTION plvstr.rvrs(str text)
+RETURNS text
+AS $$ SELECT plvstr.rvrs($1,1,NULL);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rvrs(text) IS 'Reverse string or part of string';
+
+CREATE FUNCTION pg_catalog.lnnvl(bool)
+RETURNS bool
+AS 'MODULE_PATHNAME','ora_lnnvl'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION pg_catalog.lnnvl(bool) IS '';
+
+-- can't overwrite PostgreSQL functions!!!!
+
+CREATE SCHEMA oracle;
+
+CREATE FUNCTION oracle.substr(str text, start int)
+RETURNS text
+AS 'MODULE_PATHNAME','oracle_substr2'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION oracle.substr(text, int) IS 'Returns substring started on start_in to end';
+
+CREATE FUNCTION oracle.substr(str text, start int, len int)
+RETURNS text
+AS 'MODULE_PATHNAME','oracle_substr3'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION oracle.substr(text, int, int) IS 'Returns substring started on start_in len chars';
+
+-- emulation of dual table
+CREATE VIEW public.dual AS SELECT 'X'::varchar AS dummy;
+REVOKE ALL ON public.dual FROM PUBLIC;
+GRANT SELECT, REFERENCES ON public.dual TO PUBLIC;
+
+-- others functions
+
+CREATE FUNCTION nvl(anyelement, anyelement)
+RETURNS anyelement
+AS 'MODULE_PATHNAME','ora_nvl'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION nvl(anyelement, anyelement) IS '';
+
+CREATE FUNCTION nvl2(anyelement, anyelement, anyelement)
+RETURNS anyelement
+AS 'MODULE_PATHNAME','ora_nvl2'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION nvl2(anyelement, anyelement, anyelement) IS '';
+
+CREATE FUNCTION decode(anyelement, anyelement, text)
+RETURNS text
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, text, text)
+RETURNS text
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text)
+RETURNS text
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, text)
+RETURNS text
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text)
+RETURNS text
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, text, anyelement, text, anyelement, text, text)
+RETURNS text
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bpchar)
+RETURNS bpchar
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bpchar, bpchar)
+RETURNS bpchar
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar)
+RETURNS bpchar
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, bpchar)
+RETURNS bpchar
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar)
+RETURNS bpchar
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bpchar, anyelement, bpchar, anyelement, bpchar, bpchar)
+RETURNS bpchar
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, integer, integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, integer, anyelement, integer, anyelement, integer, integer)
+RETURNS integer
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bigint)
+RETURNS bigint
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bigint, bigint)
+RETURNS bigint
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint)
+RETURNS bigint
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, bigint)
+RETURNS bigint
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint)
+RETURNS bigint
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, bigint, anyelement, bigint, anyelement, bigint, bigint)
+RETURNS bigint
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, numeric)
+RETURNS numeric
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, numeric, numeric)
+RETURNS numeric
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric)
+RETURNS numeric
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, numeric)
+RETURNS numeric
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric)
+RETURNS numeric
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, numeric, anyelement, numeric, anyelement, numeric, numeric)
+RETURNS numeric
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, date)
+RETURNS date
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, date, date)
+RETURNS date
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date)
+RETURNS date
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, date)
+RETURNS date
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date)
+RETURNS date
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, date, anyelement, date, anyelement, date, date)
+RETURNS date
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, time)
+RETURNS time
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, time, time)
+RETURNS time
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time)
+RETURNS time
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, time)
+RETURNS time
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time)
+RETURNS time
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, time, anyelement, time, anyelement, time, time)
+RETURNS time
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamp)
+RETURNS timestamp
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamp, timestamp)
+RETURNS timestamp
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp)
+RETURNS timestamp
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, timestamp)
+RETURNS timestamp
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp)
+RETURNS timestamp
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamp, anyelement, timestamp, anyelement, timestamp, timestamp)
+RETURNS timestamp
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamptz)
+RETURNS timestamptz
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamptz, timestamptz)
+RETURNS timestamptz
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz)
+RETURNS timestamptz
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, timestamptz)
+RETURNS timestamptz
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz)
+RETURNS timestamptz
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+CREATE FUNCTION decode(anyelement, anyelement, timestamptz, anyelement, timestamptz, anyelement, timestamptz, timestamptz)
+RETURNS timestamptz
+AS 'MODULE_PATHNAME', 'ora_decode'
+LANGUAGE C IMMUTABLE;
+
+
+
+-- follow package PLVdate emulation
+
+CREATE SCHEMA plvdate;
+
+CREATE FUNCTION plvdate.add_bizdays(date, int)
+RETURNS date
+AS 'MODULE_PATHNAME','plvdate_add_bizdays'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvdate.add_bizdays(date, int) IS 'Get the date created by adding <n> business days to a date';
+
+CREATE FUNCTION plvdate.nearest_bizday(date)
+RETURNS date
+AS 'MODULE_PATHNAME','plvdate_nearest_bizday'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvdate.nearest_bizday(date) IS 'Get the nearest business date to a given date, user defined';
+
+CREATE FUNCTION plvdate.next_bizday(date)
+RETURNS date
+AS 'MODULE_PATHNAME','plvdate_next_bizday'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvdate.next_bizday(date) IS 'Get the next business date from a given date, user defined';
+
+CREATE FUNCTION plvdate.bizdays_between(date, date)
+RETURNS int
+AS 'MODULE_PATHNAME','plvdate_bizdays_between'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvdate.bizdays_between(date, date) IS 'Get the number of business days between two dates';
+
+CREATE FUNCTION plvdate.prev_bizday(date)
+RETURNS date
+AS 'MODULE_PATHNAME','plvdate_prev_bizday'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvdate.prev_bizday(date) IS 'Get the previous business date from a given date';
+
+CREATE FUNCTION plvdate.isbizday(date)
+RETURNS bool
+AS 'MODULE_PATHNAME','plvdate_isbizday'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvdate.isbizday(date) IS 'Call this function to determine if a date is a business day';
+
+CREATE FUNCTION plvdate.set_nonbizday(text)
+RETURNS void
+AS 'MODULE_PATHNAME','plvdate_set_nonbizday_dow'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.set_nonbizday(text) IS 'Set day of week as non bussines day';
+
+CREATE FUNCTION plvdate.unset_nonbizday(text)
+RETURNS void
+AS 'MODULE_PATHNAME','plvdate_unset_nonbizday_dow'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.unset_nonbizday(text) IS 'Unset day of week as non bussines day';
+
+CREATE FUNCTION plvdate.set_nonbizday(date, bool)
+RETURNS void
+AS 'MODULE_PATHNAME','plvdate_set_nonbizday_day'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.set_nonbizday(date, bool) IS 'Set day as non bussines day, if repeat is true, then day is nonbiz every year';
+
+CREATE FUNCTION plvdate.unset_nonbizday(date, bool)
+RETURNS void
+AS 'MODULE_PATHNAME','plvdate_unset_nonbizday_day'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.unset_nonbizday(date, bool) IS 'Unset day as non bussines day, if repeat is true, then day is nonbiz every year';
+
+CREATE FUNCTION plvdate.set_nonbizday(date)
+RETURNS bool
+AS $$SELECT plvdate.set_nonbizday($1, false); SELECT NULL::boolean;$$
+LANGUAGE SQL VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.set_nonbizday(date) IS 'Set day as non bussines day';
+
+CREATE FUNCTION plvdate.unset_nonbizday(date)
+RETURNS bool
+AS $$SELECT plvdate.unset_nonbizday($1, false); SELECT NULL::boolean;$$
+LANGUAGE SQL VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.unset_nonbizday(date) IS 'Unset day as non bussines day';
+
+CREATE FUNCTION plvdate.use_easter(bool)
+RETURNS void
+AS 'MODULE_PATHNAME','plvdate_use_easter'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.use_easter(bool) IS 'Easter Sunday and easter monday will be holiday';
+
+CREATE FUNCTION plvdate.use_easter()
+RETURNS bool
+AS $$SELECT plvdate.use_easter(true); SELECT NULL::boolean;$$
+LANGUAGE SQL VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.use_easter() IS 'Easter Sunday and easter monday will be holiday';
+
+CREATE FUNCTION plvdate.unuse_easter()
+RETURNS bool
+AS $$SELECT plvdate.use_easter(false); SELECT NULL::boolean;$$
+LANGUAGE SQL VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.unuse_easter() IS 'Easter Sunday and easter monday will not be holiday';
+
+CREATE FUNCTION plvdate.using_easter()
+RETURNS bool
+AS 'MODULE_PATHNAME','plvdate_using_easter'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.using_easter() IS 'Use easter?';
+
+CREATE FUNCTION plvdate.include_start(bool)
+RETURNS void
+AS 'MODULE_PATHNAME','plvdate_include_start'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.include_start(bool) IS 'Include starting date in bizdays_between calculation';
+
+CREATE FUNCTION plvdate.include_start()
+RETURNS bool
+AS $$SELECT plvdate.include_start(true); SELECT NULL::boolean;$$
+LANGUAGE SQL VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.include_start() IS '';
+
+CREATE FUNCTION plvdate.noinclude_start()
+RETURNS bool
+AS $$SELECT plvdate.include_start(false); SELECT NULL::boolean;$$
+LANGUAGE SQL VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.noinclude_start() IS '';
+
+CREATE FUNCTION plvdate.including_start()
+RETURNS bool
+AS 'MODULE_PATHNAME','plvdate_including_start'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.including_start() IS '';
+
+CREATE FUNCTION plvdate.version()
+RETURNS cstring
+AS 'MODULE_PATHNAME','plvdate_version'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.version() IS '';
+
+CREATE FUNCTION plvdate.default_holidays(text)
+RETURNS void
+AS 'MODULE_PATHNAME','plvdate_default_holidays'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.default_holidays(text) IS 'Load calendar for some nations';
+
+CREATE FUNCTION plvdate.days_inmonth(date)
+RETURNS integer
+AS 'MODULE_PATHNAME','plvdate_days_inmonth'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.days_inmonth(date) IS 'Returns number of days in month';
+
+CREATE FUNCTION plvdate.isleapyear(date)
+RETURNS bool
+AS 'MODULE_PATHNAME','plvdate_isleapyear'
+LANGUAGE C VOLATILE STRICT;
+COMMENT ON FUNCTION plvdate.isleapyear(date) IS 'Is leap year';
+
+
+-- PLVstr package
+
+
+CREATE FUNCTION plvstr.normalize(str text)
+RETURNS varchar
+AS 'MODULE_PATHNAME','plvstr_normalize'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.normalize(text) IS 'Replace white chars by space, replace  spaces by space';
+
+CREATE FUNCTION plvstr.is_prefix(str text, prefix text, cs bool)
+RETURNS bool
+AS 'MODULE_PATHNAME','plvstr_is_prefix_text'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.is_prefix(text, text, bool) IS 'Returns true, if prefix is prefix of str';
+
+CREATE FUNCTION plvstr.is_prefix(str text, prefix text)
+RETURNS bool
+AS $$ SELECT plvstr.is_prefix($1,$2,true);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.is_prefix(text, text) IS 'Returns true, if prefix is prefix of str';
+
+CREATE FUNCTION plvstr.is_prefix(str int, prefix int)
+RETURNS bool
+AS 'MODULE_PATHNAME','plvstr_is_prefix_int'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.is_prefix(int, int) IS 'Returns true, if prefix is prefix of str';
+
+CREATE FUNCTION plvstr.is_prefix(str bigint, prefix bigint)
+RETURNS bool
+AS 'MODULE_PATHNAME','plvstr_is_prefix_int64'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.is_prefix(bigint, bigint) IS 'Returns true, if prefix is prefix of str';
+
+CREATE FUNCTION plvstr.substr(str text, start int, len int)
+RETURNS varchar
+AS 'MODULE_PATHNAME','plvstr_substr3'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.substr(text, int, int) IS 'Returns substring started on start_in to end';
+
+CREATE FUNCTION plvstr.substr(str text, start int)
+RETURNS varchar
+AS 'MODULE_PATHNAME','plvstr_substr2'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.substr(text, int) IS 'Returns substring started on start_in to end';
+
+CREATE FUNCTION plvstr.instr(str text, patt text, start int, nth int)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr4'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.instr(text, text, int, int) IS 'Search pattern in string';
+
+CREATE FUNCTION plvstr.instr(str text, patt text, start int)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr3'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.instr(text, text, int) IS 'Search pattern in string';
+
+CREATE FUNCTION plvstr.instr(str text, patt text)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr2'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.instr(text, text) IS 'Search pattern in string';
+
+CREATE FUNCTION plvstr.lpart(str text, div text, start int, nth int, all_if_notfound bool)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_lpart'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.lpart(text, text, int, int, bool) IS 'Call this function to return the left part of a string';
+
+CREATE FUNCTION plvstr.lpart(str text, div text, start int, nth int)
+RETURNS text
+AS $$ SELECT plvstr.lpart($1,$2, $3, $4, false); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.lpart(text, text, int, int) IS 'Call this function to return the left part of a string';
+
+CREATE FUNCTION plvstr.lpart(str text, div text, start int)
+RETURNS text
+AS $$ SELECT plvstr.lpart($1,$2, $3, 1, false); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.lpart(text, text, int) IS 'Call this function to return the left part of a string';
+
+CREATE FUNCTION plvstr.lpart(str text, div text)
+RETURNS text
+AS $$ SELECT plvstr.lpart($1,$2, 1, 1, false); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.lpart(text, text) IS 'Call this function to return the left part of a string';
+
+CREATE FUNCTION plvstr.rpart(str text, div text, start int, nth int, all_if_notfound bool)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_rpart'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rpart(text, text, int, int, bool) IS 'Call this function to return the right part of a string';
+
+CREATE FUNCTION plvstr.rpart(str text, div text, start int, nth int)
+RETURNS text
+AS $$ SELECT plvstr.rpart($1,$2, $3, $4, false); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rpart(text, text, int, int) IS 'Call this function to return the right part of a string';
+
+CREATE FUNCTION plvstr.rpart(str text, div text, start int)
+RETURNS text
+AS $$ SELECT plvstr.rpart($1,$2, $3, 1, false); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rpart(text, text, int) IS 'Call this function to return the right part of a string';
+
+CREATE FUNCTION plvstr.rpart(str text, div text)
+RETURNS text
+AS $$ SELECT plvstr.rpart($1,$2, 1, 1, false); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rpart(text, text) IS 'Call this function to return the right part of a string';
+
+CREATE FUNCTION plvstr.lstrip(str text, substr text, num int)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_lstrip'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.lstrip(text, text, int) IS 'Call this function to remove characters from the beginning ';
+
+CREATE FUNCTION plvstr.lstrip(str text, substr text)
+RETURNS text
+AS $$ SELECT plvstr.lstrip($1, $2, 1); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.lstrip(text, text) IS 'Call this function to remove characters from the beginning ';
+
+CREATE FUNCTION plvstr.rstrip(str text, substr text, num int)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_rstrip'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rstrip(text, text, int) IS 'Call this function to remove characters from the end';
+
+CREATE FUNCTION plvstr.rstrip(str text, substr text)
+RETURNS text
+AS $$ SELECT plvstr.rstrip($1, $2, 1); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.rstrip(text, text) IS 'Call this function to remove characters from the end';
+
+
+
+CREATE FUNCTION plvstr.swap(str text, replace text, start int, length int)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_swap'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plvstr.swap(text,text, int, int) IS 'Replace a substring in a string with a specified string';
+
+CREATE FUNCTION plvstr.swap(str text, replace text)
+RETURNS text
+AS $$ SELECT plvstr.swap($1,$2,1, NULL);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.swap(text,text) IS 'Replace a substring in a string with a specified string';
+
+CREATE FUNCTION plvstr.betwn(str text, start int, _end int, inclusive bool)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_betwn_i'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.betwn(text, int, int, bool) IS 'Find the Substring Between Start and End Locations';
+
+CREATE FUNCTION plvstr.betwn(str text, start int, _end int)
+RETURNS text
+AS $$ SELECT plvstr.betwn($1,$2,$3,true);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.betwn(text, int, int) IS 'Find the Substring Between Start and End Locations';
+
+CREATE FUNCTION plvstr.betwn(str text, start text, _end text, startnth int, endnth int, inclusive bool, gotoend bool)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_betwn_c'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plvstr.betwn(text, text, text, int, int, bool, bool) IS 'Find the Substring Between Start and End Locations';
+
+CREATE FUNCTION plvstr.betwn(str text, start text, _end text)
+RETURNS text
+AS $$ SELECT plvstr.betwn($1,$2,$3,1,1,true,false);$$
+LANGUAGE SQL IMMUTABLE;
+COMMENT ON FUNCTION plvstr.betwn(text, text, text) IS 'Find the Substring Between Start and End Locations';
+
+CREATE FUNCTION plvstr.betwn(str text, start text, _end text, startnth int, endnth int)
+RETURNS text
+AS $$ SELECT plvstr.betwn($1,$2,$3,$4,$5,true,false);$$
+LANGUAGE SQL IMMUTABLE;
+COMMENT ON FUNCTION plvstr.betwn(text, text, text, int, int) IS 'Find the Substring Between Start and End Locations';
+
+CREATE SCHEMA plvchr;
+
+CREATE FUNCTION plvchr.nth(str text, n int)
+RETURNS text
+AS 'MODULE_PATHNAME','plvchr_nth'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.nth(text, int) IS 'Call this function to return the Nth character in a string';
+
+CREATE FUNCTION plvchr.first(str text)
+RETURNS varchar
+AS 'MODULE_PATHNAME','plvchr_first'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.first(text) IS 'Call this function to return the first character in a string';
+
+CREATE FUNCTION plvchr.last(str text)
+RETURNS varchar
+AS 'MODULE_PATHNAME','plvchr_last'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.last(text) IS 'Call this function to return the last character in a string';
+
+CREATE FUNCTION plvchr._is_kind(str text, kind int)
+RETURNS bool
+AS 'MODULE_PATHNAME','plvchr_is_kind_a'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr._is_kind(text, int) IS '';
+
+CREATE FUNCTION plvchr._is_kind(c int, kind int)
+RETURNS bool
+AS 'MODULE_PATHNAME','plvchr_is_kind_i'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr._is_kind(int, int) IS '';
+
+CREATE FUNCTION plvchr.is_blank(c int)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 1);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_blank(int) IS '';
+
+CREATE FUNCTION plvchr.is_blank(c text)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 1);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_blank(text) IS '';
+
+CREATE FUNCTION plvchr.is_digit(c int)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 2);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_digit(int) IS '';
+
+CREATE FUNCTION plvchr.is_digit(c text)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 2);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_digit(text) IS '';
+
+CREATE FUNCTION plvchr.is_quote(c int)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 3);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_quote(int) IS '';
+
+CREATE FUNCTION plvchr.is_quote(c text)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 3);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_quote(text) IS '';
+
+CREATE FUNCTION plvchr.is_other(c int)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 4);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_other(int) IS '';
+
+CREATE FUNCTION plvchr.is_other(c text)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 4);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_other(text) IS '';
+
+CREATE FUNCTION plvchr.is_letter(c int)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 5);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_letter(int) IS '';
+
+CREATE FUNCTION plvchr.is_letter(c text)
+RETURNS BOOL
+AS $$ SELECT plvchr._is_kind($1, 5);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.is_letter(text) IS '';
+
+CREATE FUNCTION plvchr.char_name(c text)
+RETURNS varchar
+AS 'MODULE_PATHNAME','plvchr_char_name'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.char_name(text) IS '';
+
+CREATE FUNCTION plvstr.left(str text, n int)
+RETURNS varchar
+AS 'MODULE_PATHNAME', 'plvstr_left'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.left(text, int) IS 'Returns firs num_in charaters. You can use negative num_in';
+
+CREATE FUNCTION plvstr.right(str text, n int)
+RETURNS varchar
+AS 'MODULE_PATHNAME','plvstr_right'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvstr.right(text, int) IS 'Returns last num_in charaters. You can use negative num_ni';
+
+CREATE FUNCTION plvchr.quoted1(str text)
+RETURNS varchar
+AS $$SELECT ''''||$1||'''';$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.quoted1(text) IS E'Quoted text between ''';
+
+CREATE FUNCTION plvchr.quoted2(str text)
+RETURNS varchar
+AS $$SELECT '"'||$1||'"';$$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.quoted2(text) IS 'Quoted text between "';
+
+CREATE FUNCTION plvchr.stripped(str text, char_in text)
+RETURNS varchar
+AS $$ SELECT TRANSLATE($1, 'A'||$2, 'A'); $$
+LANGUAGE SQL IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvchr.stripped(text, text) IS 'Strips a string of all instances of the specified characters';
+
+CREATE SCHEMA plvsubst;
+
+CREATE FUNCTION plvsubst.string(template_in text, values_in text[], subst text)
+RETURNS text
+AS 'MODULE_PATHNAME','plvsubst_string_array'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plvsubst.string(text, text[], text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list';
+
+CREATE FUNCTION plvsubst.string(template_in text, values_in text[])
+RETURNS text
+AS $$SELECT plvsubst.string($1,$2, NULL);$$
+LANGUAGE SQL STRICT VOLATILE;
+COMMENT ON FUNCTION plvsubst.string(text, text[]) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list';
+
+CREATE FUNCTION plvsubst.string(template_in text, vals_in text, delim_in text, subst_in text)
+RETURNS text
+AS 'MODULE_PATHNAME','plvsubst_string_string'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plvsubst.string(text, text, text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list';
+
+CREATE FUNCTION plvsubst.string(template_in text, vals_in text)
+RETURNS text
+AS 'MODULE_PATHNAME','plvsubst_string_string'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plvsubst.string(text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list';
+
+CREATE FUNCTION plvsubst.string(template_in text, vals_in text, delim_in text)
+RETURNS text
+AS 'MODULE_PATHNAME','plvsubst_string_string'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plvsubst.string(text, text, text) IS 'Scans a string for all instances of the substitution keyword and replace it with the next value in the substitution values list';
+
+CREATE FUNCTION plvsubst.setsubst(str text)
+RETURNS void
+AS 'MODULE_PATHNAME','plvsubst_setsubst'
+LANGUAGE C STRICT VOLATILE;
+COMMENT ON FUNCTION plvsubst.setsubst(text) IS 'Change the substitution keyword';
+
+CREATE FUNCTION plvsubst.setsubst()
+RETURNS void
+AS 'MODULE_PATHNAME','plvsubst_setsubst_default'
+LANGUAGE C STRICT VOLATILE;
+COMMENT ON FUNCTION plvsubst.setsubst() IS 'Change the substitution keyword to default %s';
+
+CREATE FUNCTION plvsubst.subst()
+RETURNS text
+AS 'MODULE_PATHNAME','plvsubst_subst'
+LANGUAGE C STRICT VOLATILE;
+COMMENT ON FUNCTION plvsubst.subst() IS 'Retrieve the current substitution keyword';
+
+CREATE SCHEMA dbms_utility;
+
+CREATE FUNCTION dbms_utility.format_call_stack(text)
+RETURNS text
+AS 'MODULE_PATHNAME','dbms_utility_format_call_stack1'
+LANGUAGE C STRICT VOLATILE;
+COMMENT ON FUNCTION dbms_utility.format_call_stack(text) IS 'Return formated call stack';
+
+CREATE FUNCTION dbms_utility.format_call_stack()
+RETURNS text
+AS 'MODULE_PATHNAME','dbms_utility_format_call_stack0'
+LANGUAGE C VOLATILE;
+COMMENT ON FUNCTION dbms_utility.format_call_stack() IS 'Return formated call stack';
+
+CREATE SCHEMA plvlex;
+
+CREATE FUNCTION plvlex.tokens(IN str text, IN skip_spaces bool, IN qualified_names bool,
+OUT pos int, OUT token text, OUT code int, OUT class text, OUT separator text, OUT mod text)
+RETURNS SETOF RECORD
+AS 'MODULE_PATHNAME','plvlex_tokens'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION plvlex.tokens(text,bool,bool) IS 'Parse SQL string';
+
+-- dbms_assert
+
+CREATE SCHEMA dbms_assert;
+
+CREATE FUNCTION dbms_assert.enquote_literal(str varchar)
+RETURNS varchar
+AS 'MODULE_PATHNAME','dbms_assert_enquote_literal'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION dbms_assert.enquote_literal(varchar) IS 'Add leading and trailing quotes, verify that all single quotes are paired with adjacent single quotes';
+
+CREATE FUNCTION dbms_assert.enquote_name(str varchar, loweralize boolean)
+RETURNS varchar
+AS 'MODULE_PATHNAME','dbms_assert_enquote_name'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_assert.enquote_name(varchar, boolean) IS 'Enclose name in double quotes';
+
+CREATE FUNCTION dbms_assert.enquote_name(str varchar)
+RETURNS varchar
+AS 'SELECT dbms_assert.enquote_name($1, true)'
+LANGUAGE SQL IMMUTABLE;
+COMMENT ON FUNCTION dbms_assert.enquote_name(varchar) IS 'Enclose name in double quotes';
+
+CREATE FUNCTION dbms_assert.noop(str varchar)
+RETURNS varchar
+AS 'MODULE_PATHNAME','dbms_assert_noop'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_assert.noop(varchar) IS 'Returns value without any checking.';
+
+CREATE FUNCTION dbms_assert.schema_name(str varchar)
+RETURNS varchar
+AS 'MODULE_PATHNAME','dbms_assert_schema_name'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_assert.schema_name(varchar) IS 'Verify input string is an existing schema name.';
+
+CREATE FUNCTION dbms_assert.object_name(str varchar)
+RETURNS varchar
+AS 'MODULE_PATHNAME','dbms_assert_object_name'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an existing object name.';
+
+CREATE FUNCTION dbms_assert.simple_sql_name(str varchar)
+RETURNS varchar
+AS 'MODULE_PATHNAME','dbms_assert_simple_sql_name'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an sql name.';
+
+CREATE FUNCTION dbms_assert.qualified_sql_name(str varchar)
+RETURNS varchar
+AS 'MODULE_PATHNAME','dbms_assert_qualified_sql_name'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_assert.object_name(varchar) IS 'Verify input string is an qualified sql name.';
+
+CREATE SCHEMA plunit;
+
+CREATE FUNCTION plunit.assert_true(condition boolean)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_true'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_true(condition boolean) IS 'Asserts that the condition is true';
+
+CREATE FUNCTION plunit.assert_true(condition boolean, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_true_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_true(condition boolean, message varchar) IS 'Asserts that the condition is true';
+
+CREATE FUNCTION plunit.assert_false(condition boolean)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_false'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_false(condition boolean) IS 'Asserts that the condition is false';
+
+CREATE FUNCTION plunit.assert_false(condition boolean, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_false_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_false(condition boolean, message varchar) IS 'Asserts that the condition is false';
+
+CREATE FUNCTION plunit.assert_null(actual anyelement)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_null'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_null(actual anyelement) IS 'Asserts that the actual is null';
+
+CREATE FUNCTION plunit.assert_null(actual anyelement, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_null_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_null(actual anyelement, message varchar) IS 'Asserts that the condition is null';
+
+CREATE FUNCTION plunit.assert_not_null(actual anyelement)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_not_null'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_not_null(actual anyelement) IS 'Asserts that the actual is not null';
+
+CREATE FUNCTION plunit.assert_not_null(actual anyelement, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_not_null_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_not_null(actual anyelement, message varchar) IS 'Asserts that the condition is not null';
+
+CREATE FUNCTION plunit.assert_equals(expected anyelement, actual anyelement)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_equals'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_equals(expected anyelement, actual anyelement) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.assert_equals(expected anyelement, actual anyelement, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_equals_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_equals(expected anyelement, actual anyelement, message varchar) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_equals_range'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_equals_range_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision, message varchar) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_not_equals'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_not_equals_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_not_equals(expected anyelement, actual anyelement, message varchar) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_not_equals_range'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_equals(expected double precision, actual double precision, "range" double precision) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision, message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_assert_not_equals_range_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.assert_not_equals(expected double precision, actual double precision, "range" double precision, message varchar) IS 'Asserts that expected and actual are equal';
+
+CREATE FUNCTION plunit.fail()
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_fail'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.fail() IS 'Immediately fail.';
+
+CREATE FUNCTION plunit.fail(message varchar)
+RETURNS void
+AS 'MODULE_PATHNAME','plunit_fail_message'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION plunit.fail(message varchar) IS 'Immediately fail.';
+
+-- dbms_random
+CREATE SCHEMA dbms_random;
+
+CREATE FUNCTION dbms_random.initialize(int)
+RETURNS void 
+AS 'MODULE_PATHNAME','dbms_random_initialize'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION dbms_random.initialize(int) IS 'Initialize package with a seed value';
+
+CREATE FUNCTION dbms_random.normal()
+RETURNS double precision
+AS 'MODULE_PATHNAME','dbms_random_normal'
+LANGUAGE C VOLATILE;
+COMMENT ON FUNCTION dbms_random.normal() IS 'Returns random numbers in a standard normal distribution';
+
+CREATE FUNCTION dbms_random.random()
+RETURNS integer
+AS 'MODULE_PATHNAME','dbms_random_random'
+LANGUAGE C VOLATILE;
+COMMENT ON FUNCTION dbms_random.random() IS 'Generate Random Numeric Values';
+
+CREATE FUNCTION dbms_random.seed(integer)
+RETURNS void 
+AS 'MODULE_PATHNAME','dbms_random_seed_int'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION dbms_random.seed(int) IS 'Reset the seed value';
+
+CREATE FUNCTION dbms_random.seed(text)
+RETURNS void 
+AS 'MODULE_PATHNAME','dbms_random_seed_varchar'
+LANGUAGE C IMMUTABLE STRICT;
+COMMENT ON FUNCTION dbms_random.seed(text) IS 'Reset the seed value';
+
+CREATE FUNCTION dbms_random.string(opt text, len int)
+RETURNS text
+AS 'MODULE_PATHNAME','dbms_random_string'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_random.string(text,int) IS 'Create Random Strings';
+
+CREATE FUNCTION dbms_random.terminate()
+RETURNS void 
+AS 'MODULE_PATHNAME','dbms_random_terminate'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION dbms_random.terminate() IS 'Terminate use of the Package';
+
+CREATE FUNCTION dbms_random.value(low double precision, high double precision)
+RETURNS double precision
+AS 'MODULE_PATHNAME','dbms_random_value_range'
+LANGUAGE C STRICT VOLATILE;
+COMMENT ON FUNCTION dbms_random.value(double precision, double precision) IS 'Generate Random number x, where x is greather or equal to low and less then high';
+
+CREATE FUNCTION dbms_random.value()
+RETURNS double precision 
+AS 'MODULE_PATHNAME','dbms_random_value'
+LANGUAGE C VOLATILE;
+COMMENT ON FUNCTION dbms_random.value() IS 'Generate Random number x, where x is greather or equal to 0 and less then 1';
+
+GRANT USAGE ON SCHEMA plvdate TO PUBLIC;
+GRANT USAGE ON SCHEMA plvstr TO PUBLIC;
+GRANT USAGE ON SCHEMA plvchr TO PUBLIC;
+GRANT USAGE ON SCHEMA plvsubst TO PUBLIC;
+GRANT USAGE ON SCHEMA dbms_utility TO PUBLIC;
+GRANT USAGE ON SCHEMA plvlex TO PUBLIC;
+GRANT USAGE ON SCHEMA dbms_assert TO PUBLIC;
+GRANT USAGE ON SCHEMA dbms_random TO PUBLIC;
+
+CREATE FUNCTION concat(text, text)
+RETURNS text
+AS 'MODULE_PATHNAME','ora_concat'
+LANGUAGE C IMMUTABLE;
+COMMENT ON FUNCTION concat(text, text) IS 'Concat two strings';
+
+CREATE FUNCTION concat(text, anyarray)
+RETURNS text
+AS 'SELECT concat($1, $2::text)'
+LANGUAGE sql IMMUTABLE;
+
+CREATE FUNCTION concat(anyarray, text)
+RETURNS text
+AS 'SELECT concat($1::text, $2)'
+LANGUAGE sql IMMUTABLE;
+
+CREATE FUNCTION concat(anyarray, anyarray)
+RETURNS text
+AS 'SELECT concat($1::text, $2::text)'
+LANGUAGE sql IMMUTABLE;
+
+COMMIT;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/orafunc-gp.sql
----------------------------------------------------------------------
diff --git a/contrib/orafce/orafunc-gp.sql b/contrib/orafce/orafunc-gp.sql
new file mode 100644
index 0000000..dbfa671
--- /dev/null
+++ b/contrib/orafce/orafunc-gp.sql
@@ -0,0 +1,212 @@
+-- Adjust this setting to control where the objects get created.
+\set ORA_SCHEMA oracompat
+
+CREATE SCHEMA :ORA_SCHEMA;
+
+SET search_path = :ORA_SCHEMA;
+BEGIN;
+
+-- NVL
+CREATE OR REPLACE FUNCTION nvl(anyelement, anyelement)
+RETURNS anyelement
+AS 'MODULE_PATHNAME','ora_nvl'
+LANGUAGE C IMMUTABLE;
+
+-- ADD_MONTHS
+CREATE OR REPLACE FUNCTION add_months(day date, value int)
+RETURNS date
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+-- LAST_DAY
+CREATE OR REPLACE FUNCTION last_day(value date)
+RETURNS date
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+-- NEXT_DAY
+CREATE OR REPLACE FUNCTION next_day(value date, weekday text)
+RETURNS date
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION next_day(value date, weekday integer)
+RETURNS date
+AS 'MODULE_PATHNAME', 'next_day_by_index'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+-- MONTHS_BETWEEN
+CREATE OR REPLACE FUNCTION months_between(date1 date, date2 date)
+RETURNS numeric
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+-- TRUNC
+CREATE OR REPLACE FUNCTION trunc(value timestamp with time zone, fmt text)
+RETURNS timestamp with time zone
+AS 'MODULE_PATHNAME', 'ora_timestamptz_trunc'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION trunc(value timestamp with time zone)
+RETURNS timestamp with time zone
+AS $$ SELECT trunc($1, 'DDD'); $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION trunc(value date, fmt text)
+RETURNS date
+AS 'MODULE_PATHNAME', 'ora_date_trunc'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION trunc(value date)
+RETURNS date
+AS $$ SELECT $1; $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+
+-- ROUND
+CREATE OR REPLACE FUNCTION round(value timestamp with time zone, fmt text)
+RETURNS timestamp with time zone
+AS 'MODULE_PATHNAME', 'ora_timestamptz_round'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION round(value timestamp with time zone)
+RETURNS timestamp with time zone
+AS $$ SELECT round($1, 'DDD'); $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION round(value date, fmt text)
+RETURNS date
+AS 'MODULE_PATHNAME','ora_date_round'
+LANGUAGE 'C' IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION round(value date)
+RETURNS date
+AS $$ SELECT $1; $$
+LANGUAGE 'SQL' IMMUTABLE STRICT;
+
+-- INSTR
+CREATE OR REPLACE FUNCTION instr(str text, patt text, start int, nth int)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr4'
+LANGUAGE C IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION instr(str text, patt text, start int)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr3'
+LANGUAGE C IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION instr(str text, patt text)
+RETURNS int
+AS 'MODULE_PATHNAME','plvstr_instr2'
+LANGUAGE C IMMUTABLE STRICT;
+
+-- REVERSE
+CREATE OR REPLACE FUNCTION reverse(str text, start int, _end int)
+RETURNS text
+AS 'MODULE_PATHNAME','plvstr_rvrs'
+LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION reverse(str text, start int)
+RETURNS text
+AS $$ SELECT reverse($1,$2,NULL);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION reverse(str text)
+RETURNS text
+AS $$ SELECT reverse($1,1,NULL);$$
+LANGUAGE SQL IMMUTABLE STRICT;
+
+-- CONCAT
+CREATE OR REPLACE FUNCTION concat(text, text)
+RETURNS text
+AS 'MODULE_PATHNAME','ora_concat'
+LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION concat(text, anyarray)
+RETURNS text
+AS 'SELECT concat($1, $2::text)'
+LANGUAGE sql IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION concat(anyarray, text)
+RETURNS text
+AS 'SELECT concat($1::text, $2)'
+LANGUAGE sql IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION concat(anyarray, anyarray)
+RETURNS text
+AS 'SELECT concat($1::text, $2::text)'
+LANGUAGE sql IMMUTABLE;
+
+-- NANVL
+CREATE OR REPLACE FUNCTION nanvl(float4, float4)
+RETURNS float4 AS
+$$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION nanvl(float8, float8)
+RETURNS float8 AS
+$$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION nanvl(numeric, numeric)
+RETURNS numeric AS
+$$ SELECT CASE WHEN $1 = 'NaN' THEN $2 ELSE $1 END; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+-- BITAND
+CREATE OR REPLACE FUNCTION bitand(bigint, bigint)
+RETURNS bigint
+AS $$ SELECT $1 & $2; $$
+LANGUAGE sql IMMUTABLE STRICT;
+
+-- LISTAGG
+CREATE OR REPLACE FUNCTION listagg1_transfn(text, text)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_listagg1_transfn'
+LANGUAGE C IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION listagg2_transfn(text, text, text)
+RETURNS text
+AS 'MODULE_PATHNAME','orafce_listagg2_transfn'
+LANGUAGE C IMMUTABLE;
+
+-- NVL2
+CREATE OR REPLACE FUNCTION nvl2(anyelement, anyelement, anyelement)
+RETURNS anyelement
+AS 'MODULE_PATHNAME','ora_nvl2'
+LANGUAGE C IMMUTABLE;
+
+-- LNNVL
+CREATE OR REPLACE FUNCTION lnnvl(bool)
+RETURNS bool
+AS 'MODULE_PATHNAME','ora_lnnvl'
+LANGUAGE C IMMUTABLE;
+
+-- DUMP
+CREATE OR REPLACE FUNCTION dump("any") 
+RETURNS varchar
+AS 'MODULE_PATHNAME', 'orafce_dump'
+LANGUAGE C;
+
+CREATE OR REPLACE FUNCTION dump("any", integer)
+RETURNS varchar
+AS 'MODULE_PATHNAME', 'orafce_dump'
+LANGUAGE C;
+
+-- NLSSORT
+CREATE OR REPLACE FUNCTION nlssort(text, text)
+RETURNS bytea
+AS 'MODULE_PATHNAME', 'ora_nlssort'
+LANGUAGE 'C' IMMUTABLE;
+
+-- SUBSTR
+CREATE OR REPLACE FUNCTION substr(str text, start int)
+RETURNS text
+AS 'MODULE_PATHNAME','oracle_substr2'
+LANGUAGE C IMMUTABLE STRICT;
+
+CREATE OR REPLACE FUNCTION substr(str text, start int, len int)
+RETURNS text
+AS 'MODULE_PATHNAME','oracle_substr3'
+LANGUAGE C IMMUTABLE STRICT;
+
+COMMIT;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/orafunc.h
----------------------------------------------------------------------
diff --git a/contrib/orafce/orafunc.h b/contrib/orafce/orafunc.h
new file mode 100644
index 0000000..ef2fbf3
--- /dev/null
+++ b/contrib/orafce/orafunc.h
@@ -0,0 +1,128 @@
+#ifndef __ORAFUNC__
+#define __ORAFUNC__
+
+#include "postgres.h"
+#include "catalog/catversion.h"
+#include "nodes/pg_list.h"
+#include <sys/time.h>
+#include "utils/datetime.h"
+#include "utils/datum.h"
+
+#ifndef PG_VERSION_NUM
+#define PG_VERSION_NUM		80100	/* assume 8.1. */
+#endif
+
+#define TextPCopy(t) \
+	DatumGetTextP(datumCopy(PointerGetDatum(t), false, -1))
+
+#define PG_GETARG_IF_EXISTS(n, type, defval) \
+	((PG_NARGS() > (n) && !PG_ARGISNULL(n)) ? PG_GETARG_##type(n) : (defval))
+
+/* alignment of this struct must fit for all types */
+typedef union vardata
+{
+	char	c;
+	short	s;
+	int		i;
+	long	l;
+	float	f;
+	double	d;
+	void   *p;
+} vardata;
+
+int ora_instr(text *txt, text *pattern, int start, int nth);
+int ora_mb_strlen(text *str, char **sizes, int **positions);
+int ora_mb_strlen1(text *str);
+
+/*
+ * Version compatibility
+ */
+
+#if PG_VERSION_NUM >= 80400
+extern Oid	equality_oper_funcid(Oid argtype);
+#endif
+
+#ifdef GP_VERSION_NUM
+#ifndef CStringGetTextDatum
+#define CStringGetTextDatum(s) PointerGetDatum(cstring_to_text(s))
+#endif
+char *
+text_to_cstring(const text *t);
+text *cstring_to_text(const char *c);
+text *cstring_to_text_with_len(const char *c, int n);
+#else
+#if PG_VERSION_NUM < 80400
+#define CStringGetTextDatum(c) \
+        DirectFunctionCall1(textin, CStringGetDatum(c))
+#define text_to_cstring(t) \
+        DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(t)))
+#define cstring_to_text(c) \
+        DatumGetTextP(CStringGetTextDatum(c))
+text *cstring_to_text_with_len(const char *c, int n);
+#endif
+#endif
+
+#ifdef GP_VERSION_NUM
+#define DatumGetTextPP(X)			((text *) PG_DETOAST_DATUM_PACKED(X))
+#define SET_VARSIZE(PTR, len)				SET_VARSIZE_4B  ((varattrib_4b*)(PTR), (len))
+#define PG_GETARG_TEXT_PP(n)		DatumGetTextPP(PG_GETARG_DATUM(n))
+#define VARDATA_ANY(PTR) \
+	 (VARATT_IS_1B(PTR) ? VARDATA_1B(PTR) : VARDATA_4B(PTR))
+#define VARSIZE_ANY_EXHDR(PTR) \
+	(VARATT_IS_1B_E(PTR) ? VARSIZE_1B_E(PTR)-VARHDRSZ_EXTERNAL : \
+	 (VARATT_IS_1B(PTR) ? VARSIZE_1B(PTR)-VARHDRSZ_SHORT : \
+	  VARSIZE_4B(PTR)-VARHDRSZ))
+#define att_align_nominal(cur_offset, attalign) \
+( \
+	((attalign) == 'i') ? INTALIGN(cur_offset) : \
+	 (((attalign) == 'c') ? (intptr_t) (cur_offset) : \
+	  (((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
+	   ( \
+			AssertMacro((attalign) == 's'), \
+			SHORTALIGN(cur_offset) \
+	   ))) \
+)
+#define att_addlength_pointer(cur_offset, attlen, attptr) \
+( \
+	((attlen) > 0) ? \
+	( \
+		(cur_offset) + (attlen) \
+	) \
+	: (((attlen) == -1) ? \
+	( \
+		(cur_offset) + VARSIZE_ANY(attptr) \
+	) \
+	: \
+	( \
+		AssertMacro((attlen) == -2), \
+		(cur_offset) + (strlen((char *) (attptr)) + 1) \
+	)) \
+)
+
+List *
+stringToQualifiedNameList(const char *string, const char *caller);
+
+#else
+#if PG_VERSION_NUM < 80300
+#define PGDLLIMPORT				DLLIMPORT
+#define session_timezone		global_timezone
+#define DatumGetTextPP(p)		DatumGetTextP(p)
+#define SET_VARSIZE(PTR, len)	(VARATT_SIZEP((PTR)) = (len))
+#define PG_GETARG_TEXT_PP(n)	PG_GETARG_TEXT_P((n))
+#define VARDATA_ANY(PTR)		VARDATA((PTR))
+#define VARSIZE_ANY_EXHDR(PTR)	(VARSIZE((PTR)) - VARHDRSZ)
+#define att_align_nominal(cur_offset, attalign) \
+	att_align((cur_offset), (attalign))
+#define att_addlength_pointer(cur_offset, attlen, attptr) \
+	att_addlength((cur_offset), (attlen), (attptr))
+#define stringToQualifiedNameList(string) \
+	stringToQualifiedNameList((string), "")
+typedef void *SPIPlanPtr;
+#endif
+#endif
+
+#if PG_VERSION_NUM < 80200
+#define ARR_NULLBITMAP(a)		(NULL)
+#endif
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/e74af545/contrib/orafce/others.c
----------------------------------------------------------------------
diff --git a/contrib/orafce/others.c b/contrib/orafce/others.c
new file mode 100644
index 0000000..7149210
--- /dev/null
+++ b/contrib/orafce/others.c
@@ -0,0 +1,506 @@
+#include "postgres.h"
+#include <stdlib.h>
+#include <locale.h>
+#include "catalog/pg_operator.h"
+#include "catalog/pg_type.h"
+#include "fmgr.h"
+#include "lib/stringinfo.h"
+#include "nodes/nodeFuncs.h"
+#include "nodes/pg_list.h"
+#include "nodes/primnodes.h"
+#include "parser/parse_expr.h"
+#include "parser/parse_oper.h"
+#include "utils/builtins.h"
+#include "utils/datum.h"
+#include "utils/lsyscache.h"
+#include "utils/memutils.h"
+#include "utils/syscache.h"
+#include "orafunc.h"
+#include "builtins.h"
+
+/*
+ * Source code for nlssort is taken from postgresql-nls-string
+ * package by Jan Pazdziora
+ */
+
+static char *lc_collate_cache = NULL;
+static int multiplication = 1;
+
+text *def_locale = NULL;
+
+PG_FUNCTION_INFO_V1(ora_lnnvl);
+
+Datum
+ora_lnnvl(PG_FUNCTION_ARGS)
+{
+	if (PG_ARGISNULL(0))
+		PG_RETURN_BOOL(true);
+
+	PG_RETURN_BOOL(!PG_GETARG_BOOL(0));
+}
+
+PG_FUNCTION_INFO_V1(ora_concat);
+
+Datum
+ora_concat(PG_FUNCTION_ARGS)
+{
+	text *t1;
+	text *t2;
+	int l1;
+	int l2;
+	text *result;
+
+	if (PG_ARGISNULL(0) && PG_ARGISNULL(1))
+		PG_RETURN_NULL();
+
+	if (PG_ARGISNULL(0))
+		PG_RETURN_DATUM(PG_GETARG_DATUM(1));
+
+	if (PG_ARGISNULL(1))
+		PG_RETURN_DATUM(PG_GETARG_DATUM(0));
+
+	t1 = PG_GETARG_TEXT_PP(0);
+	t2 = PG_GETARG_TEXT_PP(1);
+
+	l1 = VARSIZE_ANY_EXHDR(t1);
+	l2 = VARSIZE_ANY_EXHDR(t2);
+
+	result = palloc(l1+l2+VARHDRSZ);
+	memcpy(VARDATA(result), VARDATA_ANY(t1), l1);
+	memcpy(VARDATA(result) + l1, VARDATA_ANY(t2), l2);
+	SET_VARSIZE(result, l1 + l2 + VARHDRSZ);
+
+	PG_RETURN_TEXT_P(result);
+}
+
+
+PG_FUNCTION_INFO_V1(ora_nvl);
+
+Datum
+ora_nvl(PG_FUNCTION_ARGS)
+{
+	if (!PG_ARGISNULL(0))
+		PG_RETURN_DATUM(PG_GETARG_DATUM(0));
+
+	if (!PG_ARGISNULL(1))
+		PG_RETURN_DATUM(PG_GETARG_DATUM(1));
+
+	PG_RETURN_NULL();
+}
+
+PG_FUNCTION_INFO_V1(ora_nvl2);
+
+Datum
+ora_nvl2(PG_FUNCTION_ARGS)
+{
+	if (!PG_ARGISNULL(0))
+	{
+		if (!PG_ARGISNULL(1))
+			PG_RETURN_DATUM(PG_GETARG_DATUM(1));
+	}
+	else
+	{
+		if (!PG_ARGISNULL(2))
+			PG_RETURN_DATUM(PG_GETARG_DATUM(2));
+	}
+	PG_RETURN_NULL();
+}
+
+PG_FUNCTION_INFO_V1(ora_set_nls_sort);
+
+Datum
+ora_set_nls_sort(PG_FUNCTION_ARGS)
+{
+	text *arg = PG_GETARG_TEXT_P(0);
+
+	if (def_locale != NULL)
+	{
+		pfree(def_locale);
+		def_locale = NULL;
+	}
+
+	def_locale = (text*) MemoryContextAlloc(TopMemoryContext, VARSIZE(arg));
+	memcpy(def_locale, arg, VARSIZE(arg));
+
+	PG_RETURN_VOID();
+}
+
+static text*
+_nls_run_strxfrm(text *string, text *locale)
+{
+	char *string_str;
+	int string_len;
+
+	char *locale_str = NULL;
+	int locale_len = 0;
+
+	text *result;
+	char *tmp = NULL;
+	size_t size = 0;
+	size_t rest = 0;
+	int changed_locale = 0;
+
+	/*
+	 * Save the default, server-wide locale setting.
+	 * It should not change during the life-span of the server so it
+	 * is safe to save it only once, during the first invocation.
+	 */
+	if (!lc_collate_cache)
+	{
+		if ((lc_collate_cache = setlocale(LC_COLLATE, NULL)))
+			/* Make a copy of the locale name string. */
+			lc_collate_cache = strdup(lc_collate_cache);
+		if (!lc_collate_cache)
+			elog(ERROR, "failed to retrieve the default LC_COLLATE value");
+	}
+
+	/*
+	 * To run strxfrm, we need a zero-terminated strings.
+	 */
+	string_len = VARSIZE_ANY_EXHDR(string);
+	if (string_len < 0)
+		return NULL;
+	string_str = palloc(string_len + 1);
+	memcpy(string_str, VARDATA_ANY(string), string_len);
+
+	*(string_str + string_len) = '\0';
+
+	if (locale)
+	{
+		locale_len = VARSIZE_ANY_EXHDR(locale);
+	}
+	/*
+	 * If different than default locale is requested, call setlocale.
+	 */
+	if (locale_len > 0
+		&& (strncmp(lc_collate_cache, VARDATA_ANY(locale), locale_len)
+			|| *(lc_collate_cache + locale_len) != '\0'))
+	{
+		locale_str = palloc(locale_len + 1);
+		memcpy(locale_str, VARDATA_ANY(locale), locale_len);
+		*(locale_str + locale_len) = '\0';
+
+		/*
+		 * Try to set correct locales.
+		 * If setlocale failed, we know the default stayed the same,
+		 * co we can safely elog.
+		 */
+		if (!setlocale(LC_COLLATE, locale_str))
+			elog(ERROR, "failed to set the requested LC_COLLATE value [%s]", locale_str);
+
+		changed_locale = 1;
+	}
+
+	/*
+	 * We do TRY / CATCH / END_TRY to catch ereport / elog that might
+	 * happen during palloc. Ereport during palloc would not be
+	 * nice since it would leave the server with changed locales
+	 * setting, resulting in bad things.
+	 */
+	PG_TRY();
+	{
+
+		/*
+		 * Text transformation.
+		 * Increase the buffer until the strxfrm is able to fit.
+		 */
+		size = string_len * multiplication + 1;
+		tmp = palloc(size + VARHDRSZ);
+
+		rest = strxfrm(tmp + VARHDRSZ, string_str, size);
+		while (rest >= size)
+		{
+			pfree(tmp);
+			size = rest + 1;
+			tmp = palloc(size + VARHDRSZ);
+			rest = strxfrm(tmp + VARHDRSZ, string_str, size);
+			/*
+			 * Cache the multiplication factor so that the next
+			 * time we start with better value.
+			 */
+			if (string_len)
+				multiplication = (rest / string_len) + 2;
+		}
+	}
+	PG_CATCH ();
+	{
+		if (changed_locale) {
+			/*
+			 * Set original locale
+			 */
+			if (!setlocale(LC_COLLATE, lc_collate_cache))
+				elog(FATAL, "failed to set back the default LC_COLLATE value [%s]", lc_collate_cache);
+		}
+	}
+	PG_END_TRY ();
+
+	if (changed_locale)
+	{
+		/*
+		 * Set original locale
+		 */
+		if (!setlocale(LC_COLLATE, lc_collate_cache))
+			elog(FATAL, "failed to set back the default LC_COLLATE value [%s]", lc_collate_cache);
+		pfree(locale_str);
+	}
+	pfree(string_str);
+
+	/*
+	 * If the multiplication factor went down, reset it.
+	 */
+	if (string_len && rest < string_len * multiplication / 4)
+		multiplication = (rest / string_len) + 1;
+
+	result = (text *) tmp;
+	SET_VARSIZE(result, rest + VARHDRSZ);
+	return result;
+}
+
+PG_FUNCTION_INFO_V1(ora_nlssort);
+
+Datum
+ora_nlssort(PG_FUNCTION_ARGS)
+{
+	text *locale;
+	text *result;
+
+	if (PG_ARGISNULL(0))
+		PG_RETURN_NULL();
+	if (PG_ARGISNULL(1))
+	{
+		if (def_locale != NULL)
+			locale = def_locale;
+		else
+		{
+			locale = palloc(VARHDRSZ);
+			SET_VARSIZE(locale, VARHDRSZ);
+		}
+	}
+	else
+	{
+		locale = PG_GETARG_TEXT_PP(1);
+	}
+
+	result = _nls_run_strxfrm(PG_GETARG_TEXT_PP(0), locale);
+
+	if (! result)
+		PG_RETURN_NULL();
+
+	PG_RETURN_BYTEA_P(result);
+}
+
+PG_FUNCTION_INFO_V1(ora_decode);
+
+/*
+ * decode(lhs, [rhs, ret], ..., [default])
+ */
+Datum
+ora_decode(PG_FUNCTION_ARGS)
+{
+	int		nargs;
+	int		i;
+	int		retarg;
+
+	/* default value is last arg or NULL. */
+	nargs = PG_NARGS();
+	if (nargs % 2 == 0)
+	{
+		retarg = nargs - 1;
+		nargs -= 1;		/* ignore the last argument */
+	}
+	else
+		retarg = -1;	/* NULL */
+
+	if (PG_ARGISNULL(0))
+	{
+		for (i = 1; i < nargs; i += 2)
+		{
+			if (PG_ARGISNULL(i))
+			{
+				retarg = i + 1;
+				break;
+			}
+		}
+	}
+	else
+	{
+		FmgrInfo   *eq;
+
+		/*
+		 * On first call, get the input type's operator '=' and save at
+		 * fn_extra.
+		 */
+		if (fcinfo->flinfo->fn_extra == NULL)
+		{
+			MemoryContext	oldctx;
+			Oid				typid = get_fn_expr_argtype(fcinfo->flinfo, 0);
+			Oid				eqoid = equality_oper_funcid(typid);
+
+			oldctx = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
+			eq = palloc(sizeof(FmgrInfo));
+			fmgr_info(eqoid, eq);
+			MemoryContextSwitchTo(oldctx);
+
+			fcinfo->flinfo->fn_extra = eq;
+		}
+		else
+			eq = fcinfo->flinfo->fn_extra;
+
+		for (i = 1; i < nargs; i += 2)
+		{
+			FunctionCallInfoData	func;
+			Datum					result;
+
+			if (PG_ARGISNULL(i))
+				continue;
+
+			InitFunctionCallInfoData(func, eq, 2, NULL, NULL);
+			func.arg[0] = PG_GETARG_DATUM(0);
+			func.arg[1] = PG_GETARG_DATUM(i);
+			func.argnull[0] = false;
+			func.argnull[1] = false;
+			result = FunctionCallInvoke(&func);
+
+			if (!func.isnull && DatumGetBool(result))
+			{
+				retarg = i + 1;
+				break;
+			}
+		}
+	}
+
+	if (retarg < 0 || PG_ARGISNULL(retarg))
+		PG_RETURN_NULL();
+	else
+		PG_RETURN_DATUM(PG_GETARG_DATUM(retarg));
+}
+
+#if PG_VERSION_NUM >= 90100
+Oid
+equality_oper_funcid(Oid argtype)
+{
+	Oid	eq;
+	get_sort_group_operators(argtype, false, true, false, NULL, &eq, NULL, NULL);
+	return get_opcode(eq);
+}
+#elif PG_VERSION_NUM >= 80400
+Oid
+equality_oper_funcid(Oid argtype)
+{
+	Oid	eq;
+	get_sort_group_operators(argtype, false, true, false, NULL, &eq, NULL);
+	return get_opcode(eq);
+}
+#endif
+
+/*
+ * dump(anyexpr [,format])
+ *
+ *  the dump function returns a varchar2 value that includes the datatype code, 
+ *  the length in bytes, and the internal representation of the expression.
+ */
+PG_FUNCTION_INFO_V1(orafce_dump);
+
+static void
+appendDatum(StringInfo str, const void *ptr, size_t length, int format)
+{
+	if (!PointerIsValid(ptr))
+		appendStringInfoChar(str, ':');
+	else
+	{
+		const unsigned char *s = (const unsigned char *) ptr;
+		const char *formatstr;
+		size_t	i;
+
+		switch (format)
+		{
+			case 8:
+				formatstr = "%ho";
+				break;
+			case 10: 
+				formatstr = "%hu";
+				break;
+			case 16:
+				formatstr = "%hx";
+				break;
+			case 17:
+				formatstr = "%hc";
+				break;
+			default:
+				elog(ERROR, "unknown format");
+				formatstr  = NULL; 	/* quite compiler */
+		}
+
+		/* append a byte array with the specified format */
+		for (i = 0; i < length; i++)
+		{
+			if (i > 0)
+				appendStringInfoChar(str, ',');
+
+			/* print only ANSI visible chars */
+			if (format == 17 && (iscntrl(s[i]) || !isascii(s[i])))
+				appendStringInfoChar(str, '?');
+			else
+				appendStringInfo(str, formatstr, s[i]);
+		}
+	}
+}
+
+
+Datum
+orafce_dump(PG_FUNCTION_ARGS)
+{
+	Oid		valtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
+	List	*args;
+	int16	typlen;
+	bool	typbyval;
+	Size	length;
+	Datum	value;
+	int		format;
+	StringInfoData	str;
+
+	if (!fcinfo->flinfo || !fcinfo->flinfo->fn_expr)
+		elog(ERROR, "function is called from invalid context");
+
+	if (PG_ARGISNULL(0))
+		elog(ERROR, "argument is NULL");
+
+	value = PG_GETARG_DATUM(0);
+	format = PG_GETARG_IF_EXISTS(1, INT32, 10);
+
+	args = ((FuncExpr *) fcinfo->flinfo->fn_expr)->args;
+	valtype = exprType((Node *) list_nth(args, 0));
+
+	get_typlenbyval(valtype, &typlen, &typbyval);
+	length = datumGetSize(value, typbyval, typlen);
+
+	initStringInfo(&str);
+	appendStringInfo(&str, "Typ=%d Len=%d: ", valtype, (int) length);
+
+	if (!typbyval)
+	{
+		appendDatum(&str, DatumGetPointer(value), length, format);
+	}
+	else if (length <= 1)
+	{
+		char	v = DatumGetChar(value);
+		appendDatum(&str, &v, sizeof(char), format);
+	}
+	else if (length <= 2)
+	{
+		int16	v = DatumGetInt16(value);
+		appendDatum(&str, &v, sizeof(int16), format);
+	}
+	else if (length <= 4)
+	{
+		int32	v = DatumGetInt32(value);
+		appendDatum(&str, &v, sizeof(int32), format);
+	}
+	else
+	{
+		int64	v = DatumGetInt64(value);
+		appendDatum(&str, &v, sizeof(int64), format);
+	}
+
+	PG_RETURN_TEXT_P(cstring_to_text(str.data));
+}


Mime
View raw message