aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/typecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-03-04 10:34:25 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-03-04 10:34:25 -0500
commit3ed2005ff595d349276e5b2edeca1a8100b08c87 (patch)
tree361ca1ffdc3e816c98d45a0357c92d25ba71d760 /src/backend/commands/typecmds.c
parent0ad6f848eef267489d4aee7306c16f96454b7a64 (diff)
downloadpostgresql-3ed2005ff595d349276e5b2edeca1a8100b08c87.tar.gz
postgresql-3ed2005ff595d349276e5b2edeca1a8100b08c87.zip
Introduce macros for typalign and typstorage constants.
Our usual practice for "poor man's enum" catalog columns is to define macros for the possible values and use those, not literal constants, in C code. But for some reason lost in the mists of time, this was never done for typalign/attalign or typstorage/attstorage. It's never too late to make it better though, so let's do that. The reason I got interested in this right now is the need to duplicate some uses of the TYPSTORAGE constants in an upcoming ALTER TYPE patch. But in general, this sort of change aids greppability and readability, so it's a good idea even without any specific motivation. I may have missed a few places that could be converted, and it's even more likely that pending patches will re-introduce some hard-coded references. But that's not fatal --- there's no expectation that we'd actually change any of these values. We can clean up stragglers over time. Discussion: https://postgr.es/m/16457.1583189537@sss.pgh.pa.us
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r--src/backend/commands/typecmds.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 52097363fd6..99528bf1d58 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -132,8 +132,8 @@ DefineType(ParseState *pstate, List *names, List *parameters)
Oid elemType = InvalidOid;
char *defaultValue = NULL;
bool byValue = false;
- char alignment = 'i'; /* default alignment */
- char storage = 'p'; /* default TOAST storage method */
+ char alignment = TYPALIGN_INT; /* default alignment */
+ char storage = TYPSTORAGE_PLAIN; /* default TOAST storage method */
Oid collation = InvalidOid;
DefElem *likeTypeEl = NULL;
DefElem *internalLengthEl = NULL;
@@ -382,16 +382,16 @@ DefineType(ParseState *pstate, List *names, List *parameters)
if (pg_strcasecmp(a, "double") == 0 ||
pg_strcasecmp(a, "float8") == 0 ||
pg_strcasecmp(a, "pg_catalog.float8") == 0)
- alignment = 'd';
+ alignment = TYPALIGN_DOUBLE;
else if (pg_strcasecmp(a, "int4") == 0 ||
pg_strcasecmp(a, "pg_catalog.int4") == 0)
- alignment = 'i';
+ alignment = TYPALIGN_INT;
else if (pg_strcasecmp(a, "int2") == 0 ||
pg_strcasecmp(a, "pg_catalog.int2") == 0)
- alignment = 's';
+ alignment = TYPALIGN_SHORT;
else if (pg_strcasecmp(a, "char") == 0 ||
pg_strcasecmp(a, "pg_catalog.bpchar") == 0)
- alignment = 'c';
+ alignment = TYPALIGN_CHAR;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -402,13 +402,13 @@ DefineType(ParseState *pstate, List *names, List *parameters)
char *a = defGetString(storageEl);
if (pg_strcasecmp(a, "plain") == 0)
- storage = 'p';
+ storage = TYPSTORAGE_PLAIN;
else if (pg_strcasecmp(a, "external") == 0)
- storage = 'e';
+ storage = TYPSTORAGE_EXTERNAL;
else if (pg_strcasecmp(a, "extended") == 0)
- storage = 'x';
+ storage = TYPSTORAGE_EXTENDED;
else if (pg_strcasecmp(a, "main") == 0)
- storage = 'm';
+ storage = TYPSTORAGE_MAIN;
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -643,8 +643,8 @@ DefineType(ParseState *pstate, List *names, List *parameters)
*/
array_type = makeArrayTypeName(typeName, typeNamespace);
- /* alignment must be 'i' or 'd' for arrays */
- alignment = (alignment == 'd') ? 'd' : 'i';
+ /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
+ alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
TypeCreate(array_oid, /* force assignment of this type OID */
array_type, /* type name */
@@ -672,7 +672,7 @@ DefineType(ParseState *pstate, List *names, List *parameters)
NULL, /* binary default isn't sent either */
false, /* never passed by value */
alignment, /* see above */
- 'x', /* ARRAY is always toastable */
+ TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@@ -1078,8 +1078,8 @@ DefineDomain(CreateDomainStmt *stmt)
*/
domainArrayName = makeArrayTypeName(domainName, domainNamespace);
- /* alignment must be 'i' or 'd' for arrays */
- alignment = (alignment == 'd') ? 'd' : 'i';
+ /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for arrays */
+ alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
TypeCreate(domainArrayOid, /* force assignment of this type OID */
domainArrayName, /* type name */
@@ -1107,7 +1107,7 @@ DefineDomain(CreateDomainStmt *stmt)
NULL, /* binary default isn't sent either */
false, /* never passed by value */
alignment, /* see above */
- 'x', /* ARRAY is always toastable */
+ TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@@ -1221,8 +1221,8 @@ DefineEnum(CreateEnumStmt *stmt)
NULL, /* never a default type value */
NULL, /* binary default isn't sent either */
true, /* always passed by value */
- 'i', /* int alignment */
- 'p', /* TOAST strategy always plain */
+ TYPALIGN_INT, /* int alignment */
+ TYPSTORAGE_PLAIN, /* TOAST strategy always plain */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@@ -1261,8 +1261,8 @@ DefineEnum(CreateEnumStmt *stmt)
NULL, /* never a default type value */
NULL, /* binary default isn't sent either */
false, /* never passed by value */
- 'i', /* enums have align i, so do their arrays */
- 'x', /* ARRAY is always toastable */
+ TYPALIGN_INT, /* enums have int align, so do their arrays */
+ TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@@ -1516,8 +1516,8 @@ DefineRange(CreateRangeStmt *stmt)
get_typlenbyvalalign(rangeSubtype,
&subtyplen, &subtypbyval, &subtypalign);
- /* alignment must be 'i' or 'd' for ranges */
- alignment = (subtypalign == 'd') ? 'd' : 'i';
+ /* alignment must be TYPALIGN_INT or TYPALIGN_DOUBLE for ranges */
+ alignment = (subtypalign == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
/* Allocate OID for array type */
rangeArrayOid = AssignTypeArrayOid();
@@ -1550,7 +1550,7 @@ DefineRange(CreateRangeStmt *stmt)
NULL, /* no binary form available either */
false, /* never passed by value */
alignment, /* alignment */
- 'x', /* TOAST strategy (always extended) */
+ TYPSTORAGE_EXTENDED, /* TOAST strategy (always extended) */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */
@@ -1592,7 +1592,7 @@ DefineRange(CreateRangeStmt *stmt)
NULL, /* binary default isn't sent either */
false, /* never passed by value */
alignment, /* alignment - same as range's */
- 'x', /* ARRAY is always toastable */
+ TYPSTORAGE_EXTENDED, /* ARRAY is always toastable */
-1, /* typMod (Domains only) */
0, /* Array dimensions of typbasetype */
false, /* Type NOT NULL */