diff --git a/expected/select.out b/expected/select.out index bd5efa7..e8c95ab 100644 --- a/expected/select.out +++ b/expected/select.out @@ -1334,7 +1334,15 @@ SELECT a FROM f_test_tbl6 ORDER BY 1; (4 rows) SELECT a FROM f_test_tbl7 ORDER BY 1; -ERROR: value "9999999999" is out of range for type integer + a +------------ + 0 + 25 + 25 + 25 + 1410065407 +(5 rows) + -- Cleanup DELETE FROM f_mongo_test WHERE a != 0; DROP TABLE l_test_tbl1; diff --git a/mongo_fdw.c b/mongo_fdw.c index 0488a35..a806deb 100644 --- a/mongo_fdw.c +++ b/mongo_fdw.c @@ -1875,7 +1875,8 @@ column_types_compatible(BSON_TYPE bsonType, Oid columnTypeId) * object identifier. We can safely overload this 64-byte data * type since it's reserved for internal use in PostgreSQL. */ - if (bsonType == BSON_TYPE_OID) + if (bsonType == BSON_TYPE_OID || + bsonType == BSON_TYPE_UTF8) compatibleTypes = true; break; case DATEOID: @@ -2073,14 +2074,33 @@ column_value(BSON_ITERATOR *bsonIterator, Oid columnTypeId, break; case NAMEOID: { - char value[NAMEDATALEN]; + const char *name_val; + BSON_TYPE bsonType = bsonIterType(bsonIterator); Datum valueDatum = 0; - bson_oid_t *bsonObjectId = (bson_oid_t *) bsonIterOid(bsonIterator); - - bson_oid_to_string(bsonObjectId, value); + switch (bsonType) + { + case BSON_TYPE_OID: + { + char value[NAMEDATALEN]; + bson_oid_t *bsonObjectId = (bson_oid_t *) bsonIterOid(bsonIterator); - valueDatum = CStringGetDatum(value); + bson_oid_to_string(bsonObjectId, value); + name_val = value; + } + break; + case BSON_TYPE_UTF8: + { + name_val = bsonIterString(bsonIterator); + } + break; + default: + ereport(ERROR, + (errcode(ERRCODE_FDW_INVALID_DATA_TYPE), + errmsg("cannot convert BSON type to column type"), + errhint("Column type: %u", (uint32) columnTypeId))); + } + valueDatum = CStringGetDatum(name_val); columnValue = DirectFunctionCall3(namein, valueDatum, ObjectIdGetDatum(InvalidOid), Int32GetDatum(columnTypeMod)); diff --git a/mongo_wrapper.c b/mongo_wrapper.c index e3e2a5e..8608158 100644 --- a/mongo_wrapper.c +++ b/mongo_wrapper.c @@ -200,13 +200,13 @@ bsonIterInt32(BSON_ITERATOR *it) { int64 val = bson_iterator_long_raw(it); - if (val < PG_INT32_MIN || val > PG_INT32_MAX) + if (val < PG_INT64_MIN || val > PG_INT64_MAX) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("value \"%ld\" is out of range for type integer", val))); - return (int32) val; + return (int64) val; } case BSON_INT: return bson_iterator_int_raw(it); diff --git a/mongo_wrapper_meta.c b/mongo_wrapper_meta.c index 41e96b7..7ff8eb2 100644 --- a/mongo_wrapper_meta.c +++ b/mongo_wrapper_meta.c @@ -368,13 +368,13 @@ bsonIterInt32(BSON_ITERATOR *it) { int64 val = bson_iter_int64(it); - if (val < PG_INT32_MIN || val > PG_INT32_MAX) + if (val < PG_INT64_MIN || val > PG_INT64_MAX) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("value \"%ld\" is out of range for type integer", val))); - return (int32) val; + return (int64) val; } case BSON_TYPE_INT32: return bson_iter_int32(it);