Skip to content

Commit

Permalink
Fix deparse for CREATE DOMAIN ... NOT NULL
Browse files Browse the repository at this point in the history
The parser now adds a single entry in the `keys` array, with the string
`value`.
  • Loading branch information
msepga committed Sep 26, 2024
1 parent 36888a6 commit 6ca22b7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/postgres_deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4863,9 +4863,18 @@ static void deparseConstraint(StringInfo str, Constraint *constraint)

if (list_length(constraint->keys) > 0)
{
appendStringInfoChar(str, '(');
deparseColumnList(str, constraint->keys);
appendStringInfoString(str, ") ");
bool valueOnly = false;

if (list_length(constraint->keys) == 1) {
Node* firstKey = constraint->keys->elements[0].ptr_value;
valueOnly = IsA(firstKey, String) && !strcmp("value", ((String*)firstKey)->sval);
}

if (!valueOnly) {
appendStringInfoChar(str, '(');
deparseColumnList(str, constraint->keys);
appendStringInfoString(str, ") ");
}
}

if (list_length(constraint->fk_attrs) > 0)
Expand Down

0 comments on commit 6ca22b7

Please sign in to comment.