From 31edbadf4af45dd4eecebcb732702ec6d7ae1819 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 5 Jun 2007 21:31:09 +0000 Subject: Downgrade implicit casts to text to be assignment-only, except for the ones from the other string-category types; this eliminates a lot of surprising interpretations that the parser could formerly make when there was no directly applicable operator. Create a general mechanism that supports casts to and from the standard string types (text,varchar,bpchar) for *every* datatype, by invoking the datatype's I/O functions. These new casts are assignment-only in the to-string direction, explicit-only in the other, and therefore should create no surprising behavior. Remove a bunch of thereby-obsoleted datatype-specific casting functions. The "general mechanism" is a new expression node type CoerceViaIO that can actually convert between *any* two datatypes if their external text representations are compatible. This is more general than needed for the immediate feature, but might be useful in plpgsql or other places in future. This commit does nothing about the issue that applying the concatenation operator || to non-text types will now fail, often with strange error messages due to misinterpreting the operator as array concatenation. Since it often (not always) worked before, we should either make it succeed or at least give a more user-friendly error; but details are still under debate. Peter Eisentraut and Tom Lane --- src/backend/utils/adt/int.c | 66 +-------------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) (limited to 'src/backend/utils/adt/int.c') diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c index d6d59022077..405b16ecef8 100644 --- a/src/backend/utils/adt/int.c +++ b/src/backend/utils/adt/int.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.79 2007/02/27 23:48:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.80 2007/06/05 21:31:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,8 +18,6 @@ * int2in, int2out, int2recv, int2send * int4in, int4out, int4recv, int4send * int2vectorin, int2vectorout, int2vectorrecv, int2vectorsend - * Conversion routines: - * itoi, int2_text, int4_text * Boolean operators: * inteq, intne, intlt, intle, intgt, intge * Arithmetic operators: @@ -343,68 +341,6 @@ i4toi2(PG_FUNCTION_ARGS) PG_RETURN_INT16((int16) arg1); } -Datum -int2_text(PG_FUNCTION_ARGS) -{ - int16 arg1 = PG_GETARG_INT16(0); - text *result = (text *) palloc(7 + VARHDRSZ); /* sign,5 digits, '\0' */ - - pg_itoa(arg1, VARDATA(result)); - SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ); - PG_RETURN_TEXT_P(result); -} - -Datum -text_int2(PG_FUNCTION_ARGS) -{ - text *string = PG_GETARG_TEXT_P(0); - Datum result; - int len; - char *str; - - len = VARSIZE(string) - VARHDRSZ; - - str = palloc(len + 1); - memcpy(str, VARDATA(string), len); - *(str + len) = '\0'; - - result = DirectFunctionCall1(int2in, CStringGetDatum(str)); - pfree(str); - - return result; -} - -Datum -int4_text(PG_FUNCTION_ARGS) -{ - int32 arg1 = PG_GETARG_INT32(0); - text *result = (text *) palloc(12 + VARHDRSZ); /* sign,10 digits,'\0' */ - - pg_ltoa(arg1, VARDATA(result)); - SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ); - PG_RETURN_TEXT_P(result); -} - -Datum -text_int4(PG_FUNCTION_ARGS) -{ - text *string = PG_GETARG_TEXT_P(0); - Datum result; - int len; - char *str; - - len = VARSIZE(string) - VARHDRSZ; - - str = palloc(len + 1); - memcpy(str, VARDATA(string), len); - *(str + len) = '\0'; - - result = DirectFunctionCall1(int4in, CStringGetDatum(str)); - pfree(str); - - return result; -} - /* Cast int4 -> bool */ Datum int4_bool(PG_FUNCTION_ARGS) -- cgit v1.2.3