For some reason, CREATE TYPE has only accepted alignment specifications

of 'int4' and 'double'.  Add 'char' and 'int2' to allow user-defined types
to access the full set of supported alignments.
This commit is contained in:
Tom Lane 2001-08-03 20:47:40 +00:00
parent 8f0ee46dcb
commit fd61fbe837
3 changed files with 27 additions and 14 deletions

View 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>

View 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
{

View 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)