EnterpriseDB / mongo_fdw

PostgreSQL foreign data wrapper for MongoDB
GNU Lesser General Public License v3.0
326 stars 70 forks source link

A bug for sub query #84

Closed lifubang closed 2 years ago

lifubang commented 7 years ago

@ahsanhadi @gabbasb After merge tha patch for #64 The sub query select "dname" from "wb_domain" where ent_id = (select ent_id from "ent_account" where id = 1185); returns null. It's not correct.

both ent_id in wb_doman, and ent_id in "ent_account" are int8 type. It returns null.

But select ent_id from "ent_account" where id = 1185, returns 15755 select "dname" from "wb_domain" where ent_id = 15755, returns 'tca', It's right.

ahsanhadi commented 7 years ago

Can you please share the complete test case, we will look into this.

lifubang commented 7 years ago

Test case

/* create the regular table ent_account_test */ 
CREATE TABLE public.ent_account_test (
    login_name varchar(100) NULL DEFAULT NULL::character varying,
    ent_id int8 null,
    CONSTRAINT ent_account_test_pkey PRIMARY KEY (login_name)
)
WITH (
    OIDS=FALSE
);

CREATE INDEX ent_account_test_ent_id_index ON public.ent_account_test (ent_id);

/* init ent_account_test data */
insert into public.ent_account_test(login_name, ent_id) values('13911998129', 15755);
/* make sure the data exists */
select ent_id from "ent_account_test" where login_name='13911998129';
-- it returns 15755

/* create the foreign table domain_test */  
CREATE FOREIGN TABLE domain_test (
    _id NAME,
    dname varchar(100) NULL DEFAULT NULL::character varying,
    ent_id int8 null
)
SERVER mongo_server_master
         OPTIONS (database 'hello-world', collection 'domain_test');
;

/* init domain_test data */
insert into public.domain_test(dname, ent_id) values('tca', 15755);
/* make sure the data exists */
select "dname" from public.domain_test where ent_id=15755;
-- it returns tca

/* sub query fail */
select "dname" from "domain_test" where ent_id = (select ent_id from "ent_account_test" where login_name='13911998129');
-- it returns null
vaibhavdalvi93 commented 2 years ago

@lifubang , Are you still facing this issue with the latest HEAD? If yes, can you please provide us reproducible test case? Otherwise, can you please close this ticket?

lifubang commented 2 years ago

For this special case, we use another sql to do the same query, so I have no opportunities to check whether it has been fixed or not. Anyway, close this. Thanks.