Skip to content

Handling correct typmod for money/smallmoney during coercion and dump-restore #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
4 changes: 3 additions & 1 deletion src/backend/parser/parse_coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,9 @@ coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId,
strcmp(type_name, "nchar") == 0 ||
strcmp(type_name, "varbinary") == 0 ||
strcmp(type_name, "binary") == 0 ||
strcmp(type_name, "decimal") == 0))
strcmp(type_name, "decimal") == 0 ||
strcmp(type_name, "smallmoney") == 0||
strcmp(type_name, "money") == 0))
result->resulttypmod = baseTypeMod;

return (Node *) result;
Expand Down
8 changes: 8 additions & 0 deletions src/backend/parser/parse_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName,
check_or_set_default_typmod_hook_type check_or_set_default_typmod_hook = NULL;
validate_var_datatype_scale_hook_type validate_var_datatype_scale_hook = NULL;
handle_default_collation_hook_type handle_default_collation_hook = NULL;
get_domain_typmodin_hook_type get_domain_typmodin_hook = NULL;

/*
* LookupTypeName
Expand Down Expand Up @@ -361,6 +362,13 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)

typmodin = ((Form_pg_type) GETSTRUCT(typ))->typmodin;

/*
* Find the OID of domain's typmodin function, which is same as its basetype's typmodin OID,
* for domains like smallmoney/money and their UDTs during restore.
*/
if (get_domain_typmodin_hook)
typmodin = (*get_domain_typmodin_hook)(typ);

if (typmodin == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
Expand Down
8 changes: 8 additions & 0 deletions src/include/parser/parse_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ extern PGDLLEXPORT validate_var_datatype_scale_hook_type validate_var_datatype_s
typedef Oid (*handle_default_collation_hook_type) (Type typ, bool handle_pg_type);
extern PGDLLEXPORT handle_default_collation_hook_type handle_default_collation_hook;

/*
* Hook to find oid of typmodin function for a given domain tuple which is essentially same as
* the oid of it's basetype's typmodin function. This is only used during restore to handle domains
* like smallmoney/money and UDTs created on them.
*/
typedef Oid (*get_domain_typmodin_hook_type) (Type typ);
extern PGDLLEXPORT get_domain_typmodin_hook_type get_domain_typmodin_hook;

#endif /* PARSE_TYPE_H */