oguimbal / pg-mem

An in memory postgres DB instance for your unit tests
MIT License
1.96k stars 95 forks source link

check-in constraints assume not-null unlike postgres #269

Open rswheeldon opened 1 year ago

rswheeldon commented 1 year ago

Describe the bug

If I have a check constraint which considers values in a list and use this in Postgres, it works if the value is null. In pg-mem it breaks.

    check constraint "foo_constraint_1" is violated by some row

    🐜 This seems to be an execution error, which means that your request syntax seems okay,
        but the resulting statement cannot be executed → Probably not a pg-mem error.

    *️⃣ Reconsituted failed SQL statement: INSERT INTO foo  (x) VALUES (('Hello')), (('World')), ((null))

    👉 You can file an issue at https://github.com/oguimbal/pg-mem along with a way to reproduce this error (if you can), and  the stacktrace:

      at checkVal (node_modules/pg-mem/src/table.ts:536:23)
      at node_modules/pg-mem/src/table.ts:550:13
      at Object.before (node_modules/pg-mem/src/table.ts:406:25)
      at MemoryTable.doInsert (node_modules/pg-mem/src/table.ts:322:20)
      at Insert.performMutation (node_modules/pg-mem/src/execution/records-mutations/insert.ts:167:33)
      at Insert._doExecuteOnce (node_modules/pg-mem/src/execution/records-mutations/mutation-base.ts:61:29)
      at Insert.enumerate (node_modules/pg-mem/src/execution/records-mutations/mutation-base.ts:73:31)
          at enumerate.next (<anonymous>)
      at SelectExec.execute (node_modules/pg-mem/src/execution/select.ts:280:54)
      at node_modules/pg-mem/src/execution/statement-exec.ts:199:42

To Reproduce

create table foo (
    x varchar check ( x in ('Hello', 'World') )
);

insert into foo (x) values
    ('Hello'),
    ('World'),
    (null);

pg-mem version

2.6.3