summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/network.c
diff options
context:
space:
mode:
authorTom Lane2007-06-05 21:31:09 +0000
committerTom Lane2007-06-05 21:31:09 +0000
commit31edbadf4af45dd4eecebcb732702ec6d7ae1819 (patch)
treeb1b29b079deac806537bc3d5287f4eb325f48efa /src/backend/utils/adt/network.c
parent1120b99445a90ceba27f49e5cf86293f0628d06a (diff)
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/network.c')
-rw-r--r--src/backend/utils/adt/network.c37
1 files changed, 6 insertions, 31 deletions
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index 7a190719b89..10c1285bd60 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -1,7 +1,7 @@
/*
* PostgreSQL type definitions for the INET and CIDR types.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.70 2007/05/17 23:31:49 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.71 2007/06/05 21:31:06 tgl Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
@@ -22,7 +22,6 @@
#include "utils/inet.h"
-static inet *text_network(text *src, bool is_cidr);
static int32 network_cmp_internal(inet *a1, inet *a2);
static int bitncmp(void *l, void *r, int n);
static bool addressOK(unsigned char *a, int bits, int family);
@@ -314,35 +313,6 @@ cidr_send(PG_FUNCTION_ARGS)
}
-static inet *
-text_network(text *src, bool is_cidr)
-{
- int len = VARSIZE(src) - VARHDRSZ;
- char *str = palloc(len + 1);
-
- memcpy(str, VARDATA(src), len);
- str[len] = '\0';
-
- return network_in(str, is_cidr);
-}
-
-Datum
-text_inet(PG_FUNCTION_ARGS)
-{
- text *src = PG_GETARG_TEXT_P(0);
-
- PG_RETURN_INET_P(text_network(src, false));
-}
-
-Datum
-text_cidr(PG_FUNCTION_ARGS)
-{
- text *src = PG_GETARG_TEXT_P(0);
-
- PG_RETURN_INET_P(text_network(src, true));
-}
-
-
Datum
inet_to_cidr(PG_FUNCTION_ARGS)
{
@@ -655,6 +625,11 @@ network_host(PG_FUNCTION_ARGS)
PG_RETURN_TEXT_P(ret);
}
+/*
+ * network_show implements the inet and cidr casts to text. This is not
+ * quite the same behavior as network_out, hence we can't drop it in favor
+ * of CoerceViaIO.
+ */
Datum
network_show(PG_FUNCTION_ARGS)
{