diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2023-09-27 18:52:40 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2023-09-27 18:52:40 +0100 |
commit | ebf76f2753a91615d45f113f1535a8443fa8d076 (patch) | |
tree | cb82bc6f663156a233fbff877a03ff97959fd298 /src/backend/rewrite/rewriteHandler.c | |
parent | 9dce22033d5d2813e9f8e7d595f57ee5a38b3f8e (diff) | |
download | postgresql-ebf76f2753a91615d45f113f1535a8443fa8d076.tar.gz postgresql-ebf76f2753a91615d45f113f1535a8443fa8d076.zip |
Add TupleDescGetDefault()
This unifies some repetitive code.
Note: I didn't push the "not found" error message into the new
function, even though all existing callers would be able to make use
of it. Using the existing error handling as-is would probably require
exposing the Relation type via tupdesc.h, which doesn't seem
desirable. (Or even if we changed it to just report the OID, it would
inject the concept of a relation containing the tuple descriptor into
tupdesc.h, which might be a layering violation. Perhaps some further
improvements could be considered here separately.)
Discussion: https://www.postgresql.org/message-id/flat/52a125e4-ff9a-95f5-9f61-b87cf447e4da%40eisentraut.org
Diffstat (limited to 'src/backend/rewrite/rewriteHandler.c')
-rw-r--r-- | src/backend/rewrite/rewriteHandler.c | 16 |
1 files changed, 1 insertions, 15 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index b486ab559a8..41a362310a8 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -1246,21 +1246,7 @@ build_column_default(Relation rel, int attrno) */ if (att_tup->atthasdef) { - if (rd_att->constr && rd_att->constr->num_defval > 0) - { - AttrDefault *defval = rd_att->constr->defval; - int ndef = rd_att->constr->num_defval; - - while (--ndef >= 0) - { - if (attrno == defval[ndef].adnum) - { - /* Found it, convert string representation to node tree. */ - expr = stringToNode(defval[ndef].adbin); - break; - } - } - } + expr = TupleDescGetDefault(rd_att, attrno); if (expr == NULL) elog(ERROR, "default expression not found for attribute %d of relation \"%s\"", attrno, RelationGetRelationName(rel)); |