Skip to content

Commit

Permalink
Throw error in case type of first column of MongoDB's foreign Table n…
Browse files Browse the repository at this point in the history
…ot "name".
  • Loading branch information
ibrarahmed1974 committed Jun 6, 2014
1 parent 1fd94bc commit 2007c72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion mongo_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ MongoExecForeignInsert(EState *estate,
MONGO_CONN *mongoConnection = NULL;
Oid foreignTableId = InvalidOid;
BSON *b = NULL;
Oid typoid = InvalidOid;
Oid typoid;
Datum value;
bool isnull = false;

Expand Down Expand Up @@ -757,6 +757,9 @@ MongoExecForeignInsert(EState *estate,
if (strcmp(slot->tts_tupleDescriptor->attrs[0]->attname.data, "_id") != 0)
elog(ERROR, "first colum of MongoDB's foreign table must be \"_id\"");

if (typoid != NAMEOID)
elog(ERROR, "type of first colum of MongoDB's foreign table must be \"name\"");

if (attnum == 1)
{
/*
Expand Down
6 changes: 4 additions & 2 deletions mongo_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,13 @@ AppenMongoValue(BSON *queryDocument, const char *keyName, Datum value, bool isnu
BsonAppendStartArray(queryDocument, keyName, &t);
for (i = 0; i < num_elems; i++)
{
Datum valueDatum;
float8 valueFloat;
if (elem_nulls[i])
continue;

Datum valueDatum = DirectFunctionCall1(numeric_float8, elem_values[i]);
float8 valueFloat = DatumGetFloat8(valueDatum);
valueDatum = DirectFunctionCall1(numeric_float8, elem_values[i]);
valueFloat = DatumGetFloat8(valueDatum);
#ifdef META_DRIVER
status = BsonAppendDouble(&t, keyName, valueFloat);
#else
Expand Down

0 comments on commit 2007c72

Please sign in to comment.