oguimbal / pg-mem

An in memory postgres DB instance for your unit tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Select query failing when using condition primary_key NOT IN

diegoalzate opened this issue · comments

Describe the bug

I am using condition id NOT IN, but the ids that are being passed do not necessarily have to exist in db. So it looks something like this: SELECT * FROM table WHERE id NOT IN ('id_that_does_not_exist');

This query does work if id is not a primary key so maybe that helps to find where this originates from.

call stack

Can not retrieve entry node TypeError: Cannot read properties of undefined (reading '0')

 at BIndex.compare (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/schema/btree-index.ts:91:25)
          at BIndex.nin (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/schema/btree-index.ts:232:22)
          at nin.next (<anonymous>)
          at BIndex.enumerate (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/schema/btree-index.ts:368:20)
          at enumerate.next (<anonymous>)
          at NotInFilter.enumerate (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/transforms/not-in-filter.ts:56:27)
          at enumerate.next (<anonymous>)
          at AndFilter.enumerate (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/transforms/and-filter.ts:55:20)
          at enumerate.next (<anonymous>)
          at SelectExec.execute (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/execution/select.ts:280:54)
          at /Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/execution/statement-exec.ts:203:42
          at pushExecutionCtx (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/utils.ts:391:16)
          at /Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/execution/statement-exec.ts:192:54
          at StatementExec.niceErrors (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/execution/statement-exec.ts:221:20)
          at StatementExec.executeStatement (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/execution/statement-exec.ts:192:21)
          at DbSchema.queries (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/schema/schema.ts:130:45)
          at queries.next (<anonymous>)
          at DbSchema.query (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/schema/schema.ts:79:20)
          at MemPg.query (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-mem/src/adapters/adapters.ts:104:76)
          at /Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-promise/lib/query.js:156:27
          at new Promise (<anonymous>)
          at promise (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-promise/lib/promise-parser.js:30:20)
          at Database.$query (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-promise/lib/query.js:145:12)
          at Database.<anonymous> (/Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-promise/lib/query.js:277:23)
          at /Users/diegoalzate/Code/work/hopr/RPCh/node_modules/pg-promise/lib/database.js:333:42 {
        location: { start: 0, end: 0 },
        query: "SELECT * FROM table WHERE id NOT IN ('id','id_that_does_not_exist') AND status='READY'",
        params: undefined,
        [Symbol(errorDetailsIncluded)]: true
      }

To Reproduce

--
-- PostgreSQL database dump
-- INITIAL SCHEMA BEFORE MIGRATIONS RUN BEFORE ALL MIGRATIONS
--

-- Dumped from database version 15.1 (Debian 15.1-1.pgdg110+1)
-- Dumped by pg_dump version 15.1 (Debian 15.1-1.pgdg110+1)

--------------------------------------------------------------------------------
-- Up Migration
--------------------------------------------------------------------------------

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_table_access_method = heap;

--
-- Name: registered_nodes; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.test (
    id character varying(255) NOT NULL,
    status character varying(255) NOT NULL
);


ALTER TABLE public.test OWNER TO postgres;

--
-- Name: funding_requests funding_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.test
    ADD CONSTRAINT test_pkey PRIMARY KEY (id);


INSERT INTO public.test 
(id, status) 
VALUES 
('node1', 'active'),
('node2', 'inactive'),
('node3', 'active'),
('node4', 'inactive'),
('node5', 'active');

SELECT * FROM test WHERE id NOT IN ('entry', 'unstablePeerId');

pg-mem version

"version": "2.6.12",