diff --git a/README b/README index e0a2ae1..0f1b841 100644 --- a/README +++ b/README @@ -17,6 +17,11 @@ to install the complete compatibility environment. This can be an immense time-saver when porting large applications that rely heavily on certain MySQL functions. +Versions of PostgreSQL supported +-------------------------------- + +This package has been tested on PostgreSQL 8.1.x. + Installation ------------ @@ -124,7 +129,7 @@ this won't make any difference. * Intervals -In MySQL, intervals are not quoated, eg: +In MySQL, intervals are not quoted, eg: SELECT ADDDATE('1998-01-02', INTERVAL 31 DAY); @@ -141,7 +146,7 @@ XOR, DIV and MOD named operators cannot be implemented. Use All PostgreSQL strings are case-sensitive. All MySQL strings are case-insensitive by default. Any functions in this library that -implement string comparision use CASE-SENSITIVE comparison, just +implement string comparison use CASE-SENSITIVE comparison, just like all the other PostgreSQL string functions. * Failure to find overloaded functions diff --git a/string.sql b/string.sql index f158a0c..db73ba2 100644 --- a/string.sql +++ b/string.sql @@ -327,6 +327,350 @@ $$ IMMUTABLE STRICT LANGUAGE SQL; -- MAKE_SET() -- Not implemented +-- routine to make make_set() easier +-- note: since arrays do not support NULLs until +CREATE OR REPLACE FUNCTION _make_set(bigint, text[]) +RETURNS text AS $$ + DECLARE + up int; + i int = 1; + ret text = ''; + dat ALIAS FOR $2; + found bool = false; + mask bigint = 1; + BEGIN + up = array_upper($2, 1); + IF up > 31 THEN + RAISE EXCEPTION 'maximum array size exceeded'; + RETURN NULL; + END IF; + WHILE i <= up LOOP + IF $1 & mask <> 0 THEN + IF found = false THEN + found = true; + ELSE + ret = ret operator(pg_catalog.||) ','; + END IF; + ret = ret operator(pg_catalog.||) dat[i]; + END IF; + i = i + 1; + mask = mask << 1; + END LOOP; + RETURN ret; + END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + + +CREATE OR REPLACE FUNCTION make_set(bigint, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + +CREATE OR REPLACE FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text) +RETURNS text AS $$ + DECLARE + a text[]; + BEGIN + a = ARRAY[$2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32]; +RETURN _make_set($1, a); +END; +$$ IMMUTABLE STRICT LANGUAGE PLPGSQL; + -- MID() CREATE OR REPLACE FUNCTION mid(text, integer, integer) RETURNS text AS $$ diff --git a/uninstall.sql b/uninstall.sql index 6c203b7..dfd5f3f 100644 --- a/uninstall.sql +++ b/uninstall.sql @@ -59,6 +59,37 @@ DROP FUNCTION mid(text, integer, integer); DROP FUNCTION microsecond(time without time zone); DROP FUNCTION maketime(integer, integer, integer); DROP FUNCTION makedate(integer, integer); +DROP FUNCTION make_set(bigint, text); +DROP FUNCTION make_set(bigint, text, text); +DROP FUNCTION make_set(bigint, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); +DROP FUNCTION make_set(bigint, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); DROP FUNCTION log2(numeric); DROP FUNCTION log10(numeric); DROP FUNCTION locate(text, text); @@ -139,3 +170,4 @@ DROP FUNCTION _group_concat(text, text); DROP FUNCTION _date_to_integer(date); DROP FUNCTION _bit_xor(bigint, bigint); DROP FUNCTION _and(boolean, boolean); +DROP FUNCTION _make_set(bigint, text[]);