diff options
author | Thomas G. Lockhart <lockhart@fourpalms.org> | 2000-03-14 23:06:59 +0000 |
---|---|---|
committer | Thomas G. Lockhart <lockhart@fourpalms.org> | 2000-03-14 23:06:59 +0000 |
commit | 64568100787a5d03d036e70b32147385a35245e2 (patch) | |
tree | 4b6091aedff9deed40992a05d1cacf9ce1b54c8b /src/backend/utils/adt/oracle_compat.c | |
parent | ce543b2121a772d18e25e1efbad252dcd360df96 (diff) | |
download | postgresql-64568100787a5d03d036e70b32147385a35245e2.tar.gz postgresql-64568100787a5d03d036e70b32147385a35245e2.zip |
Implement column aliases on views "CREATE VIEW name (collist)".
Implement TIME WITH TIME ZONE type (timetz internal type).
Remap length() for character strings to CHAR_LENGTH() for SQL92
and to remove the ambiguity with geometric length() functions.
Keep length() for character strings for backward compatibility.
Shrink stored views by removing internal column name list from visible rte.
Implement min(), max() for time and timetz data types.
Implement conversion of TIME to INTERVAL.
Implement abs(), mod(), fac() for the int8 data type.
Rename some math functions to generic names:
round(), sqrt(), cbrt(), pow(), etc.
Rename NUMERIC power() function to pow().
Fix int2 factorial to calculate result in int4.
Enhance the Oracle compatibility function translate() to work with string
arguments (from Edwin Ramirez).
Modify pg_proc system table to remove OID holes.
Diffstat (limited to 'src/backend/utils/adt/oracle_compat.c')
-rw-r--r-- | src/backend/utils/adt/oracle_compat.c | 68 |
1 files changed, 42 insertions, 26 deletions
diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c index 50be811b22c..b18cbf4a208 100644 --- a/src/backend/utils/adt/oracle_compat.c +++ b/src/backend/utils/adt/oracle_compat.c @@ -1,24 +1,14 @@ /* * Edmund Mergl <E.Mergl@bawue.de> * - * $Id: oracle_compat.c,v 1.20 1999/07/15 15:20:19 momjian Exp $ + * $Id: oracle_compat.c,v 1.21 2000/03/14 23:06:37 thomas Exp $ * */ #include <ctype.h> #include "postgres.h" - -text *lower(text *string); -text *upper(text *string); -text *initcap(text *string); -text *lpad(text *string1, int4 len, text *string2); -text *rpad(text *string1, int4 len, text *string2); -text *btrim(text *string, text *set); -text *ltrim(text *string, text *set); -text *rtrim(text *string, text *set); -text *substr(text *string, int4 m, int4 n); -text *translate(text *string, char from, char to); +#include "utils/builtins.h" /******************************************************************** @@ -506,42 +496,68 @@ substr(text *string, int4 m, int4 n) * * Syntax: * - * text *translate(text *string, char from, char to) + * text *translate(text *string, text *from, text *to) * * Purpose: * * Returns string after replacing all occurences of from with * the corresponding character in to. TRANSLATE will not remove * characters. + * Modified to work with strings rather than single character + * for the substitution arguments. + * Modifications from Edwin Ramirez <ramirez@doc.mssm.edu>. * ********************************************************************/ text * -translate(text *string, char from, char to) +translate(text *string, text *from, text *to) { - text *ret; - char *ptr, - *ptr_ret; - int m; + text *ret; + char *ptr_ret, *from_ptr, *to_ptr; + char *source, *target, *temp, rep; + int m, fromlen, tolen, retlen, i; if ((string == (text *) NULL) || ((m = VARSIZE(string) - VARHDRSZ) <= 0)) return string; - ret = (text *) palloc(VARSIZE(string)); - VARSIZE(ret) = VARSIZE(string); - - ptr = VARDATA(string); - ptr_ret = VARDATA(ret); + target = (char *) palloc(VARSIZE(string) - VARHDRSZ); + source = VARDATA(string); + temp = target; + fromlen = VARSIZE(from) - VARHDRSZ; + from_ptr = VARDATA(from); + tolen = VARSIZE(to) - VARHDRSZ; + to_ptr = VARDATA(to); + retlen = 0; while (m--) { - *ptr_ret++ = *ptr == from ? to : *ptr; - ptr++; + rep = *source; + for(i=0;i<fromlen;i++) { + if(from_ptr[i] == *source) { + if(i < tolen) { + rep = to_ptr[i]; + } else { + rep = 0; + } + break; + } + } + if(rep != 0) { + *target++ = rep; + retlen++; + } + source++; } + ret = (text *) palloc(retlen + VARHDRSZ); + VARSIZE(ret) = retlen + VARHDRSZ; + ptr_ret = VARDATA(ret); + for(i=0;i<retlen;i++) { + *ptr_ret++ = temp[i]; + } + pfree(target); return ret; } - /* EOF */ |