Skip to content
Astera Technology

Why did a STRICT count column still accept minus two?

Apply the business-domain check beside storage-type validation.

Download complete case notes and answer keys ↓

Read the source and its declared rule

This original count must be present and a positive whole value. Both paths require NOT NULL. A STRICT INTEGER column enforces lossless type admission, but−2 is a valid integer. Add CHECK(quantity>0) for the supplied positive domain; do not expect STRICT to invent that rule.

Filled synthetic input
RecordInput JSON
Base input{"quantity":-2}
Download editable CSV ↓

Compare the actual paths

Corrected−2 fails CHECK275. Nonconvertible text wrong fails type 3091, so the rejection record explains which supplied requirement was missed.

Misleading and corrected outputs
PathOutput JSON
Misleading path{"error":null,"records":[{"quantity":-2}]}
Corrected path{"error":{"code":275},"records":[]}
Download editable CSV ↓
Local Node.js program: 22.23.3 or 24.14.1
import {DatabaseSync} from 'node:sqlite';
import {TextDecoder} from 'node:util';
import {inflateSync} from 'node:zlib';
import {posix} from 'node:path';
import {createHash} from 'node:crypto';
const rows=(db,sql)=>db.prepare(sql).all().map(r=>({...r}));
const failed=(action)=>{try{action();return null;}catch(e){return {code:e.errcode??e.code??e.name};}};

import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
    const db=new DatabaseSync(':memory:');try{db.exec('CREATE TABLE target(quantity INTEGER NOT NULL'+(corrected?' CHECK(quantity>0)':'')+') STRICT;');
      const error=failed(()=>db.prepare('INSERT INTO target VALUES(?)').run(i.quantity));
      return {error,records:rows(db,'SELECT * FROM target')};
    }finally{db.close();}
  };
const cases=[{"label":"misleading base","input":{"quantity":-2},"expected":{"error":null,"records":[{"quantity":-2}]},"corrected":false},{"label":"corrected base","input":{"quantity":-2},"expected":{"error":{"code":275},"records":[]},"corrected":true},{"label":"nonconvertible text rejected by type","input":{"quantity":"wrong"},"expected":{"error":{"code":3091},"records":[]},"corrected":true},{"label":"positive whole value","input":{"quantity":2},"expected":{"error":null,"records":[{"quantity":2}]},"corrected":true},{"label":"missing required whole count","input":{"quantity":null},"expected":{"error":{"code":1299},"records":[]},"corrected":true}];
for(const test of cases){
  const actual=run(test.input,test.corrected);
  assert.deepEqual(actual,test.expected,test.label);
  console.log(test.label,actual);
}
Download runnable example ↓

Check boundaries before the next load

Unconvertible text is rejected; positive 2 satisfies both type and domain. Missing quantity NULL fails NOT NULL1299 and creates no row.

Editable boundary records and expected outputs
CaseInput JSONExpected output JSON
Text fails type conversion{"quantity":"wrong"}{"error":{"code":3091},"records":[]}
Positive whole count{"quantity":2}{"error":null,"records":[{"quantity":2}]}
Missing required whole count{"quantity":null}{"error":{"code":1299},"records":[]}
Download editable CSV ↓

Does integer storage make minus two a valid count here?

Show the worked answer

No. Its type is valid but the original positive-count domain is not. The corrected target stores no−2 row.

Related resources