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
18 changes: 18 additions & 0 deletions src/backend/parser/parse_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/guc.h"

static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName,
Type typ);
Expand Down Expand Up @@ -337,11 +338,16 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
{
int32 result;
Oid typmodin;
Oid typbasetype;
Oid basetypeid;
Oid typeoid;
Datum *datums;
int n;
ListCell *l;
ArrayType *arrtypmod;
ParseCallbackState pcbstate;
const char *dump_restore = GetConfigOption("babelfishpg_tsql.dump_restore", true, false);
HeapTuple tup;

/* Return prespecified typmod if no typmod expressions */
if (typeName->typmods == NIL)
Expand All @@ -360,6 +366,18 @@ typenameTypeMod(ParseState *pstate, const TypeName *typeName, Type typ)
parser_errposition(pstate, typeName->location)));

typmodin = ((Form_pg_type) GETSTRUCT(typ))->typmodin;
typeoid = ((Form_pg_type) GETSTRUCT(typ))->oid;
typbasetype = ((Form_pg_type) GETSTRUCT(typ))->typbasetype;

if (dump_restore && (strcmp(dump_restore, "on") == 0) && !typmodin && typbasetype)
{
basetypeid = getBaseType(typeoid);
tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(basetypeid));
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for type %u", basetypeid);
typmodin = ((Form_pg_type) GETSTRUCT((Type)tup))->typmodin;
ReleaseSysCache(tup);
}

if (typmodin == InvalidOid)
ereport(ERROR,
Expand Down