diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-05 21:31:09 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-06-05 21:31:09 +0000 |
commit | 31edbadf4af45dd4eecebcb732702ec6d7ae1819 (patch) | |
tree | b1b29b079deac806537bc3d5287f4eb325f48efa /src/backend/utils/adt/float.c | |
parent | 1120b99445a90ceba27f49e5cf86293f0628d06a (diff) | |
download | postgresql-31edbadf4af45dd4eecebcb732702ec6d7ae1819.tar.gz postgresql-31edbadf4af45dd4eecebcb732702ec6d7ae1819.zip |
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
Diffstat (limited to 'src/backend/utils/adt/float.c')
-rw-r--r-- | src/backend/utils/adt/float.c | 104 |
1 files changed, 1 insertions, 103 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index f2c22937564..7a66bd4c56b 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.149 2007/02/27 23:48:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.150 2007/06/05 21:31:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1197,108 +1197,6 @@ i2tof(PG_FUNCTION_ARGS) /* - * float8_text - converts a float8 number to a text string - */ -Datum -float8_text(PG_FUNCTION_ARGS) -{ - float8 num = PG_GETARG_FLOAT8(0); - text *result; - int len; - char *str; - - str = DatumGetCString(DirectFunctionCall1(float8out, - Float8GetDatum(num))); - - len = strlen(str) + VARHDRSZ; - - result = (text *) palloc(len); - - SET_VARSIZE(result, len); - memcpy(VARDATA(result), str, (len - VARHDRSZ)); - - pfree(str); - - PG_RETURN_TEXT_P(result); -} - - -/* - * text_float8 - converts a text string to a float8 number - */ -Datum -text_float8(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(float8in, CStringGetDatum(str)); - - pfree(str); - - PG_RETURN_DATUM(result); -} - - -/* - * float4_text - converts a float4 number to a text string - */ -Datum -float4_text(PG_FUNCTION_ARGS) -{ - float4 num = PG_GETARG_FLOAT4(0); - text *result; - int len; - char *str; - - str = DatumGetCString(DirectFunctionCall1(float4out, - Float4GetDatum(num))); - - len = strlen(str) + VARHDRSZ; - - result = (text *) palloc(len); - - SET_VARSIZE(result, len); - memcpy(VARDATA(result), str, (len - VARHDRSZ)); - - pfree(str); - - PG_RETURN_TEXT_P(result); -} - - -/* - * text_float4 - converts a text string to a float4 number - */ -Datum -text_float4(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(float4in, CStringGetDatum(str)); - - pfree(str); - - PG_RETURN_DATUM(result); -} - - -/* * ======================= * RANDOM FLOAT8 OPERATORS * ======================= |