diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-30 17:05:05 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-07-30 17:05:05 +0000 |
commit | bac3e83622b588eb449eb4e26c4b1e62e7cca3d5 (patch) | |
tree | 419f9079e41450aaaaa5ed0b8c8fa849a46d5bf9 /src/backend/commands/typecmds.c | |
parent | ab9907f5e5eba6e4e17a279d07a1a9df21ec5b19 (diff) | |
download | postgresql-bac3e83622b588eb449eb4e26c4b1e62e7cca3d5.tar.gz postgresql-bac3e83622b588eb449eb4e26c4b1e62e7cca3d5.zip |
Replace the hard-wired type knowledge in TypeCategory() and IsPreferredType()
with system catalog lookups, as was foreseen to be necessary almost since
their creation. Instead put the information into two new pg_type columns,
typcategory and typispreferred. Add support for setting these when
creating a user-defined base type.
The category column is just a "char" (i.e. a poor man's enum), allowing
a crude form of user extensibility of the category list: just use an
otherwise-unused character. This seems sufficient for foreseen uses,
but we could upgrade to having an actual category catalog someday, if
there proves to be a huge demand for custom type categories.
In this patch I have attempted to hew exactly to the behavior of the
previous hardwired logic, except for introducing new type categories for
arrays, composites, and enums. In particular the default preferred state
for user-defined types remains TRUE. That seems worth revisiting, but it
should be done as a separate patch from introducing the infrastructure.
Likewise, any adjustment of the standard set of categories should be done
separately.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r-- | src/backend/commands/typecmds.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 793e9262e3e..84d8036057c 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.119 2008/06/14 18:04:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.120 2008/07/30 17:05:04 tgl Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -111,6 +111,8 @@ DefineType(List *names, List *parameters) List *analyzeName = NIL; char *defaultValue = NULL; bool byValue = false; + char category = TYPCATEGORY_USER; + bool preferred = true; char delimiter = DEFAULT_TYPDELIM; char alignment = 'i'; /* default alignment */ char storage = 'p'; /* default TOAST storage method */ @@ -188,8 +190,6 @@ DefineType(List *names, List *parameters) if (pg_strcasecmp(defel->defname, "internallength") == 0) internalLength = defGetTypeLength(defel); - else if (pg_strcasecmp(defel->defname, "externallength") == 0) - ; /* ignored -- remove after 7.3 */ else if (pg_strcasecmp(defel->defname, "input") == 0) inputName = defGetQualifiedName(defel); else if (pg_strcasecmp(defel->defname, "output") == 0) @@ -205,11 +205,26 @@ DefineType(List *names, List *parameters) else if (pg_strcasecmp(defel->defname, "analyze") == 0 || pg_strcasecmp(defel->defname, "analyse") == 0) analyzeName = defGetQualifiedName(defel); + else if (pg_strcasecmp(defel->defname, "category") == 0) + { + char *p = defGetString(defel); + + category = p[0]; + /* restrict to non-control ASCII */ + if (category < 32 || category > 126) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("invalid type category \"%s\": must be simple ASCII", + p))); + } + else if (pg_strcasecmp(defel->defname, "preferred") == 0) + preferred = defGetBoolean(defel); else if (pg_strcasecmp(defel->defname, "delimiter") == 0) { char *p = defGetString(defel); delimiter = p[0]; + /* XXX shouldn't we restrict the delimiter? */ } else if (pg_strcasecmp(defel->defname, "element") == 0) { @@ -421,6 +436,8 @@ DefineType(List *names, List *parameters) 0, /* relation kind (ditto) */ internalLength, /* internal size */ TYPTYPE_BASE, /* type-type (base type) */ + category, /* type-category */ + preferred, /* is it a preferred type? */ delimiter, /* array element delimiter */ inputOid, /* input procedure */ outputOid, /* output procedure */ @@ -457,6 +474,8 @@ DefineType(List *names, List *parameters) 0, /* relation kind (ditto) */ -1, /* internal size (always varlena) */ TYPTYPE_BASE, /* type-type (base type) */ + TYPCATEGORY_ARRAY, /* type-category (array) */ + true, /* all array types are preferred */ DEFAULT_TYPDELIM, /* array element delimiter */ F_ARRAY_IN, /* input procedure */ F_ARRAY_OUT, /* output procedure */ @@ -624,6 +643,7 @@ DefineDomain(CreateDomainStmt *stmt) Oid analyzeProcedure; bool byValue; Oid typelem; + char category; char delimiter; char alignment; char storage; @@ -705,6 +725,9 @@ DefineDomain(CreateDomainStmt *stmt) /* Storage Length */ internalLength = baseType->typlen; + /* Type Category */ + category = baseType->typcategory; + /* Array element type (in case base type is an array) */ typelem = baseType->typelem; @@ -895,6 +918,8 @@ DefineDomain(CreateDomainStmt *stmt) 0, /* relation kind (ditto) */ internalLength, /* internal size */ TYPTYPE_DOMAIN, /* type-type (domain type) */ + category, /* type-category */ + false, /* domains are never preferred types */ delimiter, /* array element delimiter */ inputProcedure, /* input procedure */ outputProcedure, /* output procedure */ @@ -1006,6 +1031,8 @@ DefineEnum(CreateEnumStmt *stmt) 0, /* relation kind (ditto) */ sizeof(Oid), /* internal size */ TYPTYPE_ENUM, /* type-type (enum type) */ + TYPCATEGORY_ENUM, /* type-category (enum type) */ + true, /* all enum types are preferred */ DEFAULT_TYPDELIM, /* array element delimiter */ F_ENUM_IN, /* input procedure */ F_ENUM_OUT, /* output procedure */ @@ -1042,6 +1069,8 @@ DefineEnum(CreateEnumStmt *stmt) 0, /* relation kind (ditto) */ -1, /* internal size (always varlena) */ TYPTYPE_BASE, /* type-type (base type) */ + TYPCATEGORY_ARRAY, /* type-category (array) */ + true, /* all array types are preferred */ DEFAULT_TYPDELIM, /* array element delimiter */ F_ARRAY_IN, /* input procedure */ F_ARRAY_OUT, /* output procedure */ |