- format_type function, in use by psql
authorPeter Eisentraut <[email protected]>
Fri, 7 Jul 2000 19:24:43 +0000 (19:24 +0000)
committerPeter Eisentraut <[email protected]>
Fri, 7 Jul 2000 19:24:43 +0000 (19:24 +0000)
- added bigint as synonym of int8
- set typelem of varlen non-array types to 0

src/backend/parser/gram.y
src/backend/utils/adt/Makefile
src/backend/utils/adt/format_type.c [new file with mode: 0644]
src/bin/psql/describe.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.h
src/include/catalog/pg_type.h
src/include/utils/builtins.h

index 98a00acb8fc0df88d39346a558167afe67d981d9..15e5b2c33465f28b5c92f7fe6fae526c6d12f2f1 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.175 2000/07/03 23:09:41 wieck Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.176 2000/07/07 19:24:35 petere Exp $
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
@@ -5779,6 +5779,8 @@ xlateSqlType(char *name)
                return "int4";
        else if (strcmp(name, "smallint") == 0)
                return "int2";
+       else if (strcmp(name, "bigint") == 0)
+               return "int8";
        else if ((strcmp(name, "real") == 0)
                         || (strcmp(name, "float") == 0))
                return "float8";
index 298e15f00009dd6ba0c274de45f796395dc89972..3bdce0998b42c83129bd89eaf2c9cdb32d8cfed0 100644 (file)
@@ -4,7 +4,7 @@
 #    Makefile for utils/adt
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.37 2000/05/29 05:45:20 tgl Exp $
+#    $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.38 2000/07/07 19:24:37 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -22,7 +22,7 @@ endif
 endif
 
 OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o chunk.o \
-       date.o datetime.o datum.o filename.o float.o \
+       date.o datetime.o datum.o filename.o float.o format_type.o \
        geo_ops.o geo_selfuncs.o int.o int8.o like.o lztext.o \
        misc.o nabstime.o name.o not_in.o numeric.o numutils.o \
        oid.o oracle_compat.o \
diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c
new file mode 100644 (file)
index 0000000..af8eaa9
--- /dev/null
@@ -0,0 +1,181 @@
+/* $Header: /cvsroot/pgsql/src/backend/utils/adt/format_type.c,v 1.1 2000/07/07 19:24:37 petere Exp $ */
+
+#include "postgres.h"
+
+#include <ctype.h>
+#include <stdarg.h>
+
+#include "fmgr.h"
+#include "catalog/pg_type.h"
+#include "utils/builtins.h"
+#include "utils/syscache.h"
+
+#define streq(a, b) (strcmp((a), (b))==0)
+#define MAX_INT32_LEN 11
+
+
+static char *
+psnprintf(size_t len, const char * fmt, ...)
+{
+       va_list ap;
+       char * buf;
+
+       buf = palloc(len);
+
+       va_start(ap, fmt);
+       vsnprintf(buf, len, fmt, ap);
+       va_end(ap);
+
+       return buf;
+}
+
+
+#define _textin(str) DirectFunctionCall1(textin, CStringGetDatum(str))
+
+
+/*
+ * SQL function: format_type(type_oid, typemod)
+ *
+ * `type_oid' is from pg_type.oid, `typemod' is from
+ * pg_attribute.atttypmod. This function will get the type name and
+ * format it and the modifier to canonical SQL format, if the type is
+ * a standard type. Otherwise you just get pg_type.typname back,
+ * double quoted if it contains funny characters.
+ *
+ * If typemod is null (in the SQL sense) then you won't get any
+ * "..(x)" type qualifiers. The result is not technically correct,
+ * because the various types interpret missing type modifiers
+ * differently, but it can be used as a convenient way to format
+ * system catalogs, e.g., pg_aggregate, in psql.
+ */
+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;
+
+       if (PG_ARGISNULL(0))
+               PG_RETURN_NULL();
+
+       type_oid = DatumGetObjectId(PG_GETARG_DATUM(0));
+
+       with_typemod = !PG_ARGISNULL(1);
+       if (with_typemod)
+               typemod = PG_GETARG_INT32(1);
+
+       tuple = SearchSysCacheTuple(TYPEOID, ObjectIdGetDatum(type_oid),
+                                                               0, 0, 0);
+
+       if (!HeapTupleIsValid(tuple))
+               PG_RETURN_TEXT_P(_textin("???"));
+
+       array_base_type = ((Form_pg_type) GETSTRUCT(tuple))->typelem;
+       typlen = ((Form_pg_type) GETSTRUCT(tuple))->typlen;
+       if (array_base_type != 0 && typlen < 0)
+       {
+               tuple = SearchSysCacheTuple(TYPEOID,
+                                                                       ObjectIdGetDatum(array_base_type),
+                                                                       0, 0, 0);
+               if (!HeapTupleIsValid(tuple))
+                       PG_RETURN_TEXT_P(_textin("???[]"));
+               is_array = true;
+       }
+       else
+               is_array = false;
+       
+
+       name =  NameStr(((Form_pg_type) GETSTRUCT(tuple))->typname);
+
+       if (streq(name, "bit"))
+       {
+               if (with_typemod)
+                       buf = psnprintf(5 + MAX_INT32_LEN + 1, "bit(%d)", (int) typemod - 4);
+               else
+                       buf = pstrdup("bit");
+       }
+
+       else if (streq(name, "bool"))
+               buf = pstrdup("boolean");
+
+       else if (streq(name, "bpchar"))
+       {
+               if (with_typemod)
+                       buf = psnprintf(11 + MAX_INT32_LEN + 1, "character(%d)", (int) typemod - 4);
+               else
+                       buf = pstrdup("character");
+       }
+
+       /* This char type is the single-byte version. You have to
+        * 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");
+
+       else if (streq(name, "int4"))
+               buf = pstrdup("integer");
+
+       else if (streq(name, "int8"))
+               buf = pstrdup("bigint");
+
+       else if (streq(name, "numeric"))
+       {
+               if (with_typemod)
+                       buf = psnprintf(10 + 2 * MAX_INT32_LEN + 1, "numeric(%d,%d)",
+                                                       ((typemod - VARHDRSZ) >> 16) & 0xffff,
+                                                       (typemod - VARHDRSZ) & 0xffff);
+               else
+                       buf = pstrdup("numeric");
+       }
+
+       else if (streq(name, "timetz"))
+               buf = pstrdup("time with time zone");
+
+       else if (streq(name, "varbit"))
+       {
+               if (with_typemod)
+                       buf = psnprintf(13 + MAX_INT32_LEN + 1, "bit varying(%d)", (int) typemod - 4);
+               else
+                       buf = pstrdup("bit varying");
+       }
+
+       else if (streq(name, "varchar"))
+       {
+               if (with_typemod)
+                       buf = psnprintf(19 + MAX_INT32_LEN + 1, "character varying(%d)", (int) typemod - 4);
+               else
+                       buf = pstrdup("character varying");
+       }
+
+       else
+       {
+               if (strspn(name, "abcdefghijklmnopqrstuvwxyz0123456789_") != strlen(name)
+                       || isdigit((int) name[0]))
+                       buf = psnprintf(strlen(name) + 3, "\"%s\"", name);
+               else
+                       buf = name;
+       }
+
+       if (is_array)
+       {
+               char * buf2 = psnprintf(strlen(buf) + 3, "%s[]", buf);
+               buf = buf2;
+       }
+
+       PG_RETURN_TEXT_P(_textin(buf));
+}
index a9285b7bb49e0a9108b452d88358595814f8573f..204ade50bf421b69faecbc72c96db12960b833be 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.21 2000/04/16 20:04:51 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.22 2000/07/07 19:24:38 petere Exp $
  */
 #include "postgres.h"
 #include "describe.h"
@@ -44,10 +44,10 @@ describeAggregates(const char *name)
         * types ones that work on all
         */
        strcpy(buf,
-                  "SELECT a.aggname AS \"Name\", t.typname AS \"Type\",\n"
+                  "SELECT a.aggname AS \"Name\", format_type(a.aggbasetype, NULL) AS \"Type\",\n"
                   "  obj_description(a.oid) as \"Description\"\n"
-                  "FROM pg_aggregate a, pg_type t\n"
-                  "WHERE a.aggbasetype = t.oid\n"
+                  "FROM pg_aggregate a\n"
+                  "WHERE a.aggbasetype <> 0\n"
                );
 
        if (name)
@@ -149,13 +149,16 @@ describeFunctions(const char *name, bool verbose)
 bool
 describeTypes(const char *name, bool verbose)
 {
-       char            buf[256 + REGEXP_CUTOFF];
+       char            buf[384 + 2 * REGEXP_CUTOFF];
        PGresult   *res;
        printQueryOpt myopt = pset.popt;
 
-       strcpy(buf, "SELECT t.typname AS \"Type\"");
+       strcpy(buf, "SELECT format_type(t.oid, NULL) AS \"Type\"");
        if (verbose)
+       {
+               strcat(buf, ",\n  t.typname AS \"Internal name\"");
                strcat(buf, ",\n  (CASE WHEN t.typlen = -1 THEN 'var'::text ELSE t.typlen::text END) as \"Size\"");
+       }
        strcat(buf, ",\n  obj_description(t.oid) as \"Description\"");
 
        /*
@@ -166,11 +169,14 @@ describeTypes(const char *name, bool verbose)
 
        if (name)
        {
-               strcat(buf, "  AND t.typname ~ '^");
+               /* accept either internal or external type name */
+               strcat(buf, "  AND (format_type(t.oid, NULL) ~ '^");
+               strncat(buf, name, REGEXP_CUTOFF);
+               strcat(buf, "' OR t.typname ~ '^");
                strncat(buf, name, REGEXP_CUTOFF);
-               strcat(buf, "' ");
+               strcat(buf, "')");
        }
-       strcat(buf, "ORDER BY t.typname;");
+       strcat(buf, "\nORDER BY \"Type\";");
 
        res = PSQLexec(buf);
        if (!res)
@@ -198,18 +204,13 @@ describeOperators(const char *name)
 
        strcpy(buf,
                   "SELECT o.oprname AS \"Op\",\n"
-                  "       t1.typname AS \"Left arg\",\n"
-                  "       t2.typname AS \"Right arg\",\n"
-                  "       t0.typname AS \"Result\",\n"
+                  "       format_type(o.oprleft, NULL) AS \"Left arg\",\n"
+                  "       format_type(o.oprright, NULL) AS \"Right arg\",\n"
+                  "       format_type(p.prorettype, NULL) AS \"Result\",\n"
                   "       obj_description(p.oid) as \"Description\"\n"
-                  "FROM   pg_proc p, pg_type t0,\n"
-                  "       pg_type t1, pg_type t2,\n"
-                  "       pg_operator o\n"
-                  "WHERE  p.prorettype = t0.oid AND\n"
-                  "       RegprocToOid(o.oprcode) = p.oid AND\n"
-                  "       p.pronargs = 2 AND\n"
-                  "       o.oprleft = t1.oid AND\n"
-                  "       o.oprright = t2.oid\n");
+                  "FROM   pg_proc p, pg_operator o\n"
+                  "WHERE  RegprocToOid(o.oprcode) = p.oid AND\n"
+                  "       p.pronargs = 2\n");
        if (name)
        {
                strcat(buf, "  AND o.oprname = '");
@@ -220,14 +221,12 @@ describeOperators(const char *name)
        strcat(buf, "\nUNION\n\n"
                   "SELECT o.oprname as \"Op\",\n"
                   "       ''::name AS \"Left arg\",\n"
-                  "       t1.typname AS \"Right arg\",\n"
-                  "       t0.typname AS \"Result\",\n"
+                  "       format_type(o.oprright, NULL) AS \"Right arg\",\n"
+                  "       format_type(o.oprresult, NULL) AS \"Result\",\n"
                   "       obj_description(p.oid) as \"Description\"\n"
-                  "FROM   pg_operator o, pg_proc p, pg_type t0, pg_type t1\n"
+                  "FROM   pg_operator o, pg_proc p\n"
                   "WHERE  RegprocToOid(o.oprcode) = p.oid AND\n"
-                  "       o.oprresult = t0.oid AND\n"
-                  "       o.oprkind = 'l' AND\n"
-                  "       o.oprright = t1.oid\n");
+                  "       o.oprkind = 'l'\n");
        if (name)
        {
                strcat(buf, "AND o.oprname = '");
@@ -237,15 +236,13 @@ describeOperators(const char *name)
 
        strcat(buf, "\nUNION\n\n"
                   "SELECT o.oprname  as \"Op\",\n"
-                  "       t1.typname AS \"Left arg\",\n"
+                  "       format_type(o.oprleft, NULL) AS \"Left arg\",\n"
                   "       ''::name AS \"Right arg\",\n"
-                  "       t0.typname AS \"Result\",\n"
+                  "       format_type(o.oprresult, NULL) AS \"Result\",\n"
                   "       obj_description(p.oid) as \"Description\"\n"
-                  "FROM   pg_operator o, pg_proc p, pg_type t0, pg_type t1\n"
+                  "FROM   pg_operator o, pg_proc p\n"
                   "WHERE  RegprocToOid(o.oprcode) = p.oid AND\n"
-                  "       o.oprresult = t0.oid AND\n"
-                  "       o.oprkind = 'r' AND\n"
-                  "       o.oprleft = t1.oid\n");
+                  "       o.oprkind = 'r'\n");
        if (name)
        {
                strcat(buf, "AND o.oprname = '");
@@ -420,7 +417,7 @@ objectDescription(const char *object)
 
        /* Type description */
        strcat(descbuf, "\nUNION ALL\n\n");
-       strcat(descbuf, "SELECT DISTINCT t.typname as \"Name\", 'type'::text as \"Object\", d.description as \"Description\"\n"
+       strcat(descbuf, "SELECT DISTINCT format_type(t.oid, NULL) as \"Name\", 'type'::text as \"Object\", d.description as \"Description\"\n"
                   "FROM pg_type t, pg_description d\n"
                   "WHERE t.oid = d.objoid\n");
        if (object)
@@ -589,13 +586,13 @@ describeTableDetails(const char *name, bool desc)
 
 
        /* Get column info */
-       strcpy(buf, "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum");
+       strcpy(buf, "SELECT a.attname, format_type(a.atttypid, a.atttypmod), a.attnotnull, a.atthasdef, a.attnum");
        if (desc)
                strcat(buf, ", obj_description(a.oid)");
-       strcat(buf, "\nFROM pg_class c, pg_attribute a, pg_type t\n"
+       strcat(buf, "\nFROM pg_class c, pg_attribute a\n"
                   "WHERE c.relname = '");
        strncat(buf, name, NAMEDATALEN);
-       strcat(buf, "'\n  AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid\n"
+       strcat(buf, "'\n  AND a.attnum > 0 AND a.attrelid = c.oid\n"
                   "ORDER BY a.attnum");
 
        res = PSQLexec(buf);
@@ -628,61 +625,12 @@ describeTableDetails(const char *name, bool desc)
 
        for (i = 0; i < PQntuples(res); i++)
        {
-               int4            attypmod = atoi(PQgetvalue(res, i, 3));
-               const char *attype = PQgetvalue(res, i, 1);
-               const char *typename;
-               bool            isarray = false;
-
                /* Name */
                cells[i * cols + 0] = PQgetvalue(res, i, 0);    /* don't free this
                                                                                                                 * afterwards */
-
                /* Type */
-               if (attype[0] == '_')
-               {
-                       isarray = true;
-                       attype++;
-               }
-               /* (convert some internal type names to SQL'ish) */
-               if (strcmp(attype, "int2") == 0)
-                       typename = "smallint";
-               else if (strcmp(attype, "int4") == 0)
-                       typename = "integer";
-               else if (strcmp(attype, "int8") == 0)
-                       typename = "bigint";
-               else if (strcmp(attype, "bool") == 0)
-                       typename = "boolean";
-               else
-                       typename = attype;
-               /* more might need to be added when date/time types are sorted out */
-
-               cells[i * cols + 1] = xmalloc(NAMEDATALEN + 16);
-               if (strcmp(typename, "bpchar") == 0)
-               {
-                       if (attypmod != -1)
-                               sprintf(cells[i * cols + 1], "char(%d)", attypmod - VARHDRSZ);
-                       else
-                               sprintf(cells[i * cols + 1], "char()");
-               }
-               else if (strcmp(typename, "varchar") == 0)
-               {
-                       if (attypmod != -1)
-                               sprintf(cells[i * cols + 1], "varchar(%d)", attypmod - VARHDRSZ);
-                       else
-                               sprintf(cells[i * cols + 1], "varchar()");
-               }
-               else if (strcmp(typename, "numeric") == 0)
-               {
-                       sprintf(cells[i * cols + 1], "numeric(%d,%d)",
-                                       ((attypmod - VARHDRSZ) >> 16) & 0xffff,
-                                       (attypmod - VARHDRSZ) & 0xffff);
-               }
-               else
-                       strcpy(cells[i * cols + 1], typename);
-
-               if (isarray)
-                       strcat(cells[i * cols + 1], "[]");
-
+               cells[i * cols + 1] = PQgetvalue(res, i, 1);    /* don't free this
+                                                                                                                * either*/
 
                /* Extra: not null and default */
                /* (I'm cutting off the 'default' string at 128) */
@@ -690,17 +638,17 @@ describeTableDetails(const char *name, bool desc)
                {
                        cells[i * cols + 2] = xmalloc(128 + 128);
                        cells[i * cols + 2][0] = '\0';
-                       if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
+                       if (strcmp(PQgetvalue(res, i, 2), "t") == 0)
                                strcat(cells[i * cols + 2], "not null");
 
                        /* handle "default" here */
-                       if (strcmp(PQgetvalue(res, i, 5), "t") == 0)
+                       if (strcmp(PQgetvalue(res, i, 3), "t") == 0)
                        {
                                PGresult   *result;
 
                                sprintf(buf, "SELECT substring(d.adsrc for 128) FROM pg_attrdef d, pg_class c\n"
                                                "WHERE c.relname = '%s' AND c.oid = d.adrelid AND d.adnum = %s",
-                                               name, PQgetvalue(res, i, 6));
+                                               name, PQgetvalue(res, i, 4));
 
                                result = PSQLexec(buf);
                                if (!result)
@@ -721,7 +669,7 @@ describeTableDetails(const char *name, bool desc)
 
                /* Description */
                if (desc)
-                       cells[i * cols + cols - 1] = PQgetvalue(res, i, 7);
+                       cells[i * cols + cols - 1] = PQgetvalue(res, i, 5);
        }
 
        /* Make title */
@@ -926,7 +874,6 @@ describeTableDetails(const char *name, bool desc)
 
        for (i = 0; i < PQntuples(res); i++)
        {
-               free(cells[i * cols + 1]);
                if (tableinfo.relkind == 'r')
                        free(cells[i * cols + 2]);
        }
index 1fd691784b623c79c2ce7226d09cc598526844a6..0d4aec6c7ec25995cbf3bb637b2689ed6ddad1b6 100644 (file)
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catversion.h,v 1.35 2000/07/06 05:48:22 tgl Exp $
+ * $Id: catversion.h,v 1.36 2000/07/07 19:24:41 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     200007061
+#define CATALOG_VERSION_NO     200007071
 
 #endif
index 575fa5ee660f3111d57e22bb2487a38b09bc7251..cdf2b06ea339f3d08cd2fcce43adb2ad66616620 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_proc.h,v 1.144 2000/07/07 18:49:54 momjian Exp $
+ * $Id: pg_proc.h,v 1.145 2000/07/07 19:24:41 petere Exp $
  *
  * NOTES
  *       The script catalog/genbki.sh reads this file and generates .bki
@@ -1330,7 +1330,8 @@ DATA(insert OID = 1079 (  varcharcmp         PGUID 11 f t t t 2 f 23 "1043 1043" 100
 DESCR("less-equal-greater");
 DATA(insert OID = 1080 (  hashbpchar      PGUID 12 f t t t 1 f 23 "1042" 100 0 0 100  hashbpchar - ));
 DESCR("hash");
-
+DATA(insert OID = 1081 (  format_type      PGUID 12 f t t f 2 f 25 "26 23" 100 0 0 100 format_type - ));
+DESCR("format a type oid and atttypmod to canonical SQL");
 DATA(insert OID = 1084 (  date_in                 PGUID 12 f t f t 1 f 1082 "0" 100 0 0 100    date_in - ));
 DESCR("(internal)");
 DATA(insert OID = 1085 (  date_out                PGUID 12 f t f t 1 f 23 "0" 100 0 0 100  date_out - ));
index 69e37eb99698455f3016c1faa8edd2bbcfcb497f..c77c3c40943e20aa9e362f47bee2aa1099100906 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_type.h,v 1.91 2000/07/06 05:48:27 tgl Exp $
+ * $Id: pg_type.h,v 1.92 2000/07/07 19:24:41 petere Exp $
  *
  * NOTES
  *       the genbki.sh script reads this file and generates .bki
@@ -40,13 +40,13 @@ CATALOG(pg_type) BOOTSTRAP
 {
        NameData        typname;
        int4            typowner;
-       int2            typlen;
 
        /*
         * typlen is the number of bytes we use to represent a value of this
         * type, e.g. 4 for an int4.  But for a variable length type, typlen
         * is -1.
         */
+       int2            typlen;
        int2            typprtlen;
 
        /*
@@ -60,7 +60,6 @@ CATALOG(pg_type) BOOTSTRAP
         * true for type float4, for example.
         */
        bool            typbyval;
-       char            typtype;
 
        /*
         * typtype is 'b' for a basic type and 'c' for a catalog type (ie a
@@ -68,21 +67,26 @@ CATALOG(pg_type) BOOTSTRAP
         * in pg_class. (Why do we need an entry in pg_type for classes,
         * anyway?)
         */
+       char            typtype;
        bool            typisdefined;
        char            typdelim;
        Oid                     typrelid;               /* 0 if not a class type */
-       Oid                     typelem;
 
        /*
-        * typelem is 0 if this is not an array type.  If this is an array
-        * type, typelem is the OID of the type of the elements of the array
-        * (it identifies another row in Table pg_type).
+        * If typelem is not 0 then it identifies another row in pg_type.
+        * The current type can then be subscripted like an array yielding
+        * values of type typelem. A non-zero typelem does not guarantee
+        * this type to be an array type; ordinary fixed-length types can
+        * also be subscripted (e.g., oidvector). Variable-length types
+        * can *not* be turned into pseudo-arrays like that. Hence, the
+        * way to determine whether a type is an array type is typelem !=
+        * 0 and typlen < 0.
         */
+       Oid                     typelem;
        regproc         typinput;
        regproc         typoutput;
        regproc         typreceive;
        regproc         typsend;
-       char            typalign;
 
        /* ----------------
         * typalign is the alignment required when storing a value of this
@@ -106,7 +110,7 @@ CATALOG(pg_type) BOOTSTRAP
         * compiler will lay out the field in a struct representing a table row.
         * ----------------
         */
-       char            typstorage;
+       char            typalign;
 
        /* ----------------
         * typstorage tells if the type is prepared for toasting and what
@@ -118,6 +122,8 @@ CATALOG(pg_type) BOOTSTRAP
         * 'm' MAIN       like 'x' but try to keep in main tuple
         * ----------------
         */
+       char            typstorage;
+
        text            typdefault;             /* VARIABLE LENGTH FIELD */
 } FormData_pg_type;
 
@@ -168,7 +174,7 @@ DATA(insert OID = 16 (      bool       PGUID  1   1 t b t \054 0   0 boolin boolout bool
 DESCR("boolean, 'true'/'false'");
 #define BOOLOID                        16
 
-DATA(insert OID = 17 ( bytea      PGUID -1  -1 f b t \054 0  18 byteain byteaout byteain byteaout i p _null_ ));
+DATA(insert OID = 17 ( bytea      PGUID -1  -1 f b t \054 0  0 byteain byteaout byteain byteaout i p _null_ ));
 DESCR("variable-length string, binary values escaped");
 #define BYTEAOID               17
 
@@ -200,7 +206,7 @@ DATA(insert OID = 24 (      regproc    PGUID  4  16 t b t \054 0   0 regprocin regpro
 DESCR("registered procedure");
 #define REGPROCOID             24
 
-DATA(insert OID = 25 ( text       PGUID -1  -1 f b t \054 0  18 textin textout textin textout i x _null_ ));
+DATA(insert OID = 25 ( text       PGUID -1  -1 f b t \054 0  0 textin textout textin textout i x _null_ ));
 DESCR("variable-length string, no limit specified");
 #define TEXTOID                        25
 
@@ -261,7 +267,7 @@ DESCR("geometric point '(x, y)'");
 DATA(insert OID = 601 (  lseg     PGUID 32  48 f b t \054 0 600 lseg_in lseg_out lseg_in lseg_out d p _null_ ));
 DESCR("geometric line segment '(pt1,pt2)'");
 #define LSEGOID                        601
-DATA(insert OID = 602 (  path     PGUID -1  -1 f b t \054 0 600 path_in path_out path_in path_out d p _null_ ));
+DATA(insert OID = 602 (  path     PGUID -1  -1 f b t \054 0 0 path_in path_out path_in path_out d p _null_ ));
 DESCR("geometric path '(pt1,...)'");
 #define PATHOID                        602
 DATA(insert OID = 603 (  box      PGUID 32 100 f b t \073 0 600 box_in box_out box_in box_out d p _null_ ));
@@ -296,7 +302,7 @@ DESCR("relative, limited-range time interval (Unix delta time)");
 DATA(insert OID = 704 (  tinterval PGUID 12  47 f b t \054 0   0 tintervalin tintervalout tintervalin tintervalout i p _null_ ));
 DESCR("(abstime,abstime), time interval");
 #define TINTERVALOID   704
-DATA(insert OID = 705 (  unknown   PGUID -1  -1 f b t \054 0   18 textin textout textin textout i p _null_ ));
+DATA(insert OID = 705 (  unknown   PGUID -1  -1 f b t \054 0   0 textin textout textin textout i p _null_ ));
 DESCR("");
 #define UNKNOWNOID             705
 
@@ -362,10 +368,10 @@ DATA(insert OID = 1034 (  _aclitem         PGUID -1 -1 f b t \054 0 1033 array_in array
 DATA(insert OID = 1040 (  _macaddr      PGUID -1 -1 f b t \054 0  829 array_in array_out array_in array_out i p _null_ ));
 DATA(insert OID = 1041 (  _inet    PGUID -1 -1 f b t \054 0  869 array_in array_out array_in array_out i p _null_ ));
 DATA(insert OID = 651  (  _cidr    PGUID -1 -1 f b t \054 0  650 array_in array_out array_in array_out i p _null_ ));
-DATA(insert OID = 1042 ( bpchar                 PGUID -1  -1 f b t \054 0      18 bpcharin bpcharout bpcharin bpcharout i p _null_ ));
+DATA(insert OID = 1042 ( bpchar                 PGUID -1  -1 f b t \054 0      0 bpcharin bpcharout bpcharin bpcharout i p _null_ ));
 DESCR("char(length), blank-padded string, fixed storage length");
 #define BPCHAROID              1042
-DATA(insert OID = 1043 ( varchar        PGUID -1  -1 f b t \054 0      18 varcharin varcharout varcharin varcharout i p _null_ ));
+DATA(insert OID = 1043 ( varchar        PGUID -1  -1 f b t \054 0      0 varcharin varcharout varcharin varcharout i p _null_ ));
 DESCR("varchar(length), non-blank-padded string, variable storage length");
 #define VARCHAROID             1043
 
index f6838a593828c69a640c8a55b8d8ddbdf4d2e678..eedc97663022ae9be33b3e534bf4ce667a7bb099 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: builtins.h,v 1.120 2000/07/06 05:48:30 tgl Exp $
+ * $Id: builtins.h,v 1.121 2000/07/07 19:24:43 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -609,4 +609,7 @@ extern Datum getdatabaseencoding(PG_FUNCTION_ARGS);
 extern Datum PG_encoding_to_char(PG_FUNCTION_ARGS);
 extern Datum PG_char_to_encoding(PG_FUNCTION_ARGS);
 
+/* formatting for internal types */
+extern Datum format_type(PG_FUNCTION_ARGS);
+
 #endif  /* BUILTINS_H */