diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-03-04 10:34:25 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-03-04 10:34:25 -0500 |
commit | 3ed2005ff595d349276e5b2edeca1a8100b08c87 (patch) | |
tree | 361ca1ffdc3e816c98d45a0357c92d25ba71d760 /src/backend/commands/tablecmds.c | |
parent | 0ad6f848eef267489d4aee7306c16f96454b7a64 (diff) | |
download | postgresql-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/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 02a7c04fdb7..7a13b971649 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2030,14 +2030,14 @@ storage_name(char c) { switch (c) { - case 'p': + case TYPSTORAGE_PLAIN: return "PLAIN"; - case 'm': - return "MAIN"; - case 'x': - return "EXTENDED"; - case 'e': + case TYPSTORAGE_EXTERNAL: return "EXTERNAL"; + case TYPSTORAGE_EXTENDED: + return "EXTENDED"; + case TYPSTORAGE_MAIN: + return "MAIN"; default: return "???"; } @@ -7388,13 +7388,13 @@ ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE loc storagemode = strVal(newValue); if (pg_strcasecmp(storagemode, "plain") == 0) - newstorage = 'p'; + newstorage = TYPSTORAGE_PLAIN; else if (pg_strcasecmp(storagemode, "external") == 0) - newstorage = 'e'; + newstorage = TYPSTORAGE_EXTERNAL; else if (pg_strcasecmp(storagemode, "extended") == 0) - newstorage = 'x'; + newstorage = TYPSTORAGE_EXTENDED; else if (pg_strcasecmp(storagemode, "main") == 0) - newstorage = 'm'; + newstorage = TYPSTORAGE_MAIN; else { ereport(ERROR, @@ -7426,7 +7426,7 @@ ATExecSetStorage(Relation rel, const char *colName, Node *newValue, LOCKMODE loc * safety check: do not allow toasted storage modes unless column datatype * is TOAST-aware. */ - if (newstorage == 'p' || TypeIsToastable(attrtuple->atttypid)) + if (newstorage == TYPSTORAGE_PLAIN || TypeIsToastable(attrtuple->atttypid)) attrtuple->attstorage = newstorage; else ereport(ERROR, |