For some reason, CREATE TYPE has only accepted alignment specifications
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Aug 2001 20:47:40 +0000 (20:47 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 3 Aug 2001 20:47:40 +0000 (20:47 +0000)
of 'int4' and 'double'.  Add 'char' and 'int2' to allow user-defined types
to access the full set of supported alignments.

doc/src/sgml/ref/create_type.sgml
src/backend/commands/define.c
src/bin/pg_dump/pg_dump.c

index cd00b357d3c2df1941bd40657dc97ca8197fe23c..1693063ad384b1edc452d5df359a7476eca0204c 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.19 2001/03/24 02:35:25 thomas Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.20 2001/08/03 20:47:40 tgl Exp $
 Postgres documentation
 -->
 
@@ -153,7 +153,8 @@ CREATE TYPE <replaceable class="parameter">typename</replaceable> ( INPUT = <rep
       <listitem>
        <para>
         Storage alignment requirement of the data type.  If specified, must
-   be '<literal>int4</literal>' or '<literal>double</literal>';
+   be '<literal>char</literal>', '<literal>int2</literal>',
+   '<literal>int4</literal>', or '<literal>double</literal>';
    the default is '<literal>int4</literal>'.
        </para>
       </listitem>
index a3316fc89afffc6cc4ca3fe12aa9c21f7f1deade..f88343fa91e8655e18c9066fab87562a578eda4f 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.57 2001/06/21 18:25:54 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.58 2001/08/03 20:47:40 tgl Exp $
  *
  * DESCRIPTION
  *   The "DefineFoo" routines take the parse tree and pick out the
@@ -547,7 +547,7 @@ DefineType(char *typeName, List *parameters)
    char        delimiter = DEFAULT_TYPDELIM;
    char       *shadow_type;
    List       *pl;
-   char        alignment = 'i';/* default alignment */
+   char        alignment = 'i'; /* default alignment */
    char        storage = 'p';  /* default storage in TOAST */
 
    /*
@@ -593,15 +593,26 @@ DefineType(char *typeName, List *parameters)
        {
            char       *a = defGetString(defel);
 
+           /*
+            * Note: if argument was an unquoted identifier, parser will have
+            * applied xlateSqlType() to it, so be prepared to recognize
+            * translated type names as well as the nominal form.
+            */
            if (strcasecmp(a, "double") == 0)
                alignment = 'd';
+           else if (strcasecmp(a, "float8") == 0)
+               alignment = 'd';
            else if (strcasecmp(a, "int4") == 0)
                alignment = 'i';
+           else if (strcasecmp(a, "int2") == 0)
+               alignment = 's';
+           else if (strcasecmp(a, "char") == 0)
+               alignment = 'c';
+           else if (strcasecmp(a, "bpchar") == 0)
+               alignment = 'c';
            else
-           {
                elog(ERROR, "DefineType: \"%s\" alignment not recognized",
                     a);
-           }
        }
        else if (strcasecmp(defel->defname, "storage") == 0)
        {
@@ -616,10 +627,8 @@ DefineType(char *typeName, List *parameters)
            else if (strcasecmp(a, "main") == 0)
                storage = 'm';
            else
-           {
                elog(ERROR, "DefineType: \"%s\" storage not recognized",
                     a);
-           }
        }
        else
        {
index c2bcbce44500cb4e457fb7d9d37568d7eb2a94e8..c4c9bc7e118573fb62306764b015338aadcd06b9 100644 (file)
@@ -22,7 +22,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.217 2001/08/03 19:43:05 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.218 2001/08/03 20:47:40 tgl Exp $
  *
  * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
  *
@@ -3190,19 +3190,22 @@ dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
            (*deps)[depIdx++] = strdup(tinfo[i].typelem);
        }
 
-       /* XXX these are all the aligns currently handled by DefineType */
-       if (strcmp(tinfo[i].typalign, "i") == 0)
+       if (strcmp(tinfo[i].typalign, "c") == 0)
+           appendPQExpBuffer(q, ", alignment = char");
+       else if (strcmp(tinfo[i].typalign, "s") == 0)
+           appendPQExpBuffer(q, ", alignment = int2");
+       else if (strcmp(tinfo[i].typalign, "i") == 0)
            appendPQExpBuffer(q, ", alignment = int4");
        else if (strcmp(tinfo[i].typalign, "d") == 0)
            appendPQExpBuffer(q, ", alignment = double");
 
        if (strcmp(tinfo[i].typstorage, "p") == 0)
            appendPQExpBuffer(q, ", storage = plain");
-       if (strcmp(tinfo[i].typstorage, "e") == 0)
+       else if (strcmp(tinfo[i].typstorage, "e") == 0)
            appendPQExpBuffer(q, ", storage = external");
-       if (strcmp(tinfo[i].typstorage, "x") == 0)
+       else if (strcmp(tinfo[i].typstorage, "x") == 0)
            appendPQExpBuffer(q, ", storage = extended");
-       if (strcmp(tinfo[i].typstorage, "m") == 0)
+       else if (strcmp(tinfo[i].typstorage, "m") == 0)
            appendPQExpBuffer(q, ", storage = main");
 
        if (tinfo[i].passedbyvalue)