Skip to content

Commit ed82740

Browse files
authored
Handling correct typmod for money/smallmoney during coercion and dump-restore (babelfish-for-postgresql#575)
This PR handles the dump/restore case for smallmoney/money and handles typmod for these dataype while coercing to domain. Signed-off-by: Tanya Gupta [email protected] Extension PR : babelfish-for-postgresql/babelfish_extensions#3719 Issues Resolved BABEL-5512
1 parent 82c678d commit ed82740

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/backend/parser/parse_coerce.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,9 @@ coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId,
797797
strcmp(type_name, "nchar") == 0 ||
798798
strcmp(type_name, "varbinary") == 0 ||
799799
strcmp(type_name, "binary") == 0 ||
800-
strcmp(type_name, "decimal") == 0))
800+
strcmp(type_name, "decimal") == 0 ||
801+
strcmp(type_name, "smallmoney") == 0||
802+
strcmp(type_name, "money") == 0))
801803
result->resulttypmod = baseTypeMod;
802804

803805
return (Node *) result;

src/backend/parser/parse_type.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName,
3333
check_or_set_default_typmod_hook_type check_or_set_default_typmod_hook = NULL;
3434
validate_var_datatype_scale_hook_type validate_var_datatype_scale_hook = NULL;
3535
handle_default_collation_hook_type handle_default_collation_hook = NULL;
36+
get_domain_typmodin_hook_type get_domain_typmodin_hook = NULL;
3637

3738
/*
3839
* LookupTypeName
@@ -361,6 +362,12 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
361362

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

365+
/*
366+
* Find the OID of domain's typmodin function, which is same as its basetype's typmodin OID.
367+
*/
368+
if (get_domain_typmodin_hook)
369+
typmodin = (*get_domain_typmodin_hook)(typ);
370+
364371
if (typmodin == InvalidOid)
365372
ereport(ERROR,
366373
(errcode(ERRCODE_SYNTAX_ERROR),

src/include/parser/parse_type.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,11 @@ extern PGDLLEXPORT validate_var_datatype_scale_hook_type validate_var_datatype_s
7272
typedef Oid (*handle_default_collation_hook_type) (Type typ, bool handle_pg_type);
7373
extern PGDLLEXPORT handle_default_collation_hook_type handle_default_collation_hook;
7474

75+
/*
76+
* Hook to find oid of typmodin function for a given domain which is essentially same as
77+
* the oid of it's basetype's typmodin function.
78+
*/
79+
typedef Oid (*get_domain_typmodin_hook_type) (Type typ);
80+
extern PGDLLIMPORT get_domain_typmodin_hook_type get_domain_typmodin_hook;
81+
7582
#endif /* PARSE_TYPE_H */

0 commit comments

Comments
 (0)