aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/parser/gram.y9
-rw-r--r--src/backend/utils/adt/format_type.c108
-rw-r--r--src/backend/utils/adt/regproc.c49
3 files changed, 96 insertions, 70 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 15e5b2c3346..8836d29cc9f 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.176 2000/07/07 19:24:35 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.177 2000/07/09 21:30:10 petere Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -3944,7 +3944,7 @@ Numeric: FLOAT opt_float
;
numeric: FLOAT { $$ = xlateSqlType("float"); }
- | DOUBLE PRECISION { $$ = xlateSqlType("float"); }
+ | DOUBLE PRECISION { $$ = xlateSqlType("float8"); }
| DECIMAL { $$ = xlateSqlType("decimal"); }
| DEC { $$ = xlateSqlType("decimal"); }
| NUMERIC { $$ = xlateSqlType("numeric"); }
@@ -5781,8 +5781,9 @@ xlateSqlType(char *name)
return "int2";
else if (strcmp(name, "bigint") == 0)
return "int8";
- else if ((strcmp(name, "real") == 0)
- || (strcmp(name, "float") == 0))
+ else if (strcmp(name, "real") == 0)
+ return "float4";
+ else if (strcmp(name, "float") == 0)
return "float8";
else if (strcmp(name, "decimal") == 0)
return "numeric";
diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c
index af8eaa95441..9be79de3948 100644
--- a/src/backend/utils/adt/format_type.c
+++ b/src/backend/utils/adt/format_type.c
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.1 2000/07/07 19:24:37 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.2 2000/07/09 21:30:12 petere Exp $ */
#include "postgres.h"
@@ -12,6 +12,7 @@
#define streq(a, b) (strcmp((a), (b))==0)
#define MAX_INT32_LEN 11
+#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
static char *
@@ -30,7 +31,9 @@ psnprintf(size_t len, const char * fmt, ...)
}
-#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
+static char *
+format_type_internal(Oid type_oid, int32 typemod, bool with_typemod);
+
/*
@@ -51,15 +54,10 @@ psnprintf(size_t len, const char * fmt, ...)
Datum
format_type(PG_FUNCTION_ARGS)
{
- Oid type_oid;
- bool with_typemod;
- int32 typemod = 0;
- char * buf;
- char * name;
- Oid array_base_type;
- int16 typlen;
- bool is_array;
- HeapTuple tuple;
+ Oid type_oid;
+ bool with_typemod;
+ int32 typemod = 0;
+ char *result;
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
@@ -70,11 +68,31 @@ format_type(PG_FUNCTION_ARGS)
if (with_typemod)
typemod = PG_GETARG_INT32(1);
+ result = format_type_internal(type_oid, typemod, with_typemod);
+
+ PG_RETURN_TEXT_P(_textin(result));
+}
+
+
+
+static char *
+format_type_internal(Oid type_oid, int32 typemod, bool with_typemod)
+{
+ HeapTuple tuple;
+ Oid array_base_type;
+ int16 typlen;
+ bool is_array;
+ char *name;
+ char *buf;
+
+ if (type_oid == InvalidOid)
+ return "-";
+
tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(type_oid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- PG_RETURN_TEXT_P(_textin("???"));
+ return "???";
array_base_type = ((Form_pg_type) GETSTRUCT(tuple))->typelem;
typlen = ((Form_pg_type) GETSTRUCT(tuple))->typlen;
@@ -84,15 +102,15 @@ format_type(PG_FUNCTION_ARGS)
ObjectIdGetDatum(array_base_type),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- PG_RETURN_TEXT_P(_textin("???[]"));
+ return "???[]";
is_array = true;
}
else
is_array = false;
-
name = NameStr(((Form_pg_type) GETSTRUCT(tuple))->typname);
+
if (streq(name, "bit"))
{
if (with_typemod)
@@ -116,14 +134,13 @@ format_type(PG_FUNCTION_ARGS)
* double-quote it to get at it in the parser. */
else if (streq(name, "char"))
buf = pstrdup("\"char\"");
-#if 0
- /* The parser has these backwards, so leave as is for now. */
+
else if (streq(name, "float4"))
buf = pstrdup("real");
else if (streq(name, "float8"))
buf = pstrdup("double precision");
-#endif
+
else if (streq(name, "int2"))
buf = pstrdup("smallint");
@@ -177,5 +194,60 @@ format_type(PG_FUNCTION_ARGS)
buf = buf2;
}
- PG_RETURN_TEXT_P(_textin(buf));
+ return buf;
+}
+
+
+
+/*
+ * oidvectortypes - converts a vector of type OIDs to "typname" list
+ *
+ * The interface for this function is wrong: it should be told how many
+ * OIDs are significant in the input vector, so that trailing InvalidOid
+ * argument types can be recognized.
+ */
+Datum
+oidvectortypes(PG_FUNCTION_ARGS)
+{
+ int numargs;
+ int num;
+ Oid *oidArray = (Oid *) PG_GETARG_POINTER(0);
+ char *result;
+ size_t total;
+ size_t left;
+
+ /* Try to guess how many args there are :-( */
+ numargs = 0;
+ for (num = 0; num < FUNC_MAX_ARGS; num++)
+ {
+ if (oidArray[num] != InvalidOid)
+ numargs = num + 1;
+ }
+
+ total = 20 * numargs + 1;
+ result = palloc(total);
+ result[0] = '\0';
+ left = total - 1;
+
+ for (num = 0; num < numargs; num++)
+ {
+ char * typename = format_type_internal(oidArray[num], 0, false);
+
+ if (left < strlen(typename) + 2)
+ {
+ total += strlen(typename) + 2;
+ result = repalloc(result, total);
+ left += strlen(typename) + 2;
+ }
+
+ if (num > 0)
+ {
+ strcat(result, ", ");
+ left -= 2;
+ }
+ strcat(result, typename);
+ left -= strlen(typename);
+ }
+
+ PG_RETURN_TEXT_P(_textin(result));
}
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 6660d15f1d6..84c4694115d 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.57 2000/07/03 23:09:52 wieck Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/regproc.c,v 1.58 2000/07/09 21:30:12 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -238,53 +238,6 @@ regprocout(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(result);
}
-/*
- * oidvectortypes - converts a vector of type OIDs to "typname" list
- *
- * The interface for this function is wrong: it should be told how many
- * OIDs are significant in the input vector, so that trailing InvalidOid
- * argument types can be recognized.
- */
-Datum
-oidvectortypes(PG_FUNCTION_ARGS)
-{
- Oid *oidArray = (Oid *) PG_GETARG_POINTER(0);
- HeapTuple typetup;
- text *result;
- int numargs,
- num;
-
- /* Try to guess how many args there are :-( */
- numargs = 0;
- for (num = 0; num < FUNC_MAX_ARGS; num++)
- {
- if (oidArray[num] != InvalidOid)
- numargs = num + 1;
- }
-
- result = (text *) palloc((NAMEDATALEN + 1) * numargs + VARHDRSZ + 1);
- *VARDATA(result) = '\0';
-
- for (num = 0; num < numargs; num++)
- {
- typetup = SearchSysCacheTuple(TYPEOID,
- ObjectIdGetDatum(oidArray[num]),
- 0, 0, 0);
- if (HeapTupleIsValid(typetup))
- {
- char *s;
-
- s = NameStr(((Form_pg_type) GETSTRUCT(typetup))->typname);
- StrNCpy(VARDATA(result) + strlen(VARDATA(result)), s,
- NAMEDATALEN);
- strcat(VARDATA(result), " ");
- }
- else
- strcat(VARDATA(result), "- ");
- }
- VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
- PG_RETURN_TEXT_P(result);
-}
/*****************************************************************************