Skip to content
Astera Technology

Why did an INSERT default leave the imported state null?

Use default insertion only when the source explicitly requests the default.

Download complete case notes and answer keys ↓

Read the source and its declared rule

This original target allows null and declares DEFAULT draft. Input defaultRequested=true means use that database default, not explicitly store null. INSERT DEFAULT VALUES requests it; binding null supplies a value and does not invoke the default.

Filled synthetic input
RecordInput JSON
Base input{"defaultRequested":true,"value":null}
Download editable CSV ↓

Compare the actual paths

Correct state is draft. When defaultRequested=false, the supplied null or ready is intentionally stored as given.

Misleading and corrected outputs
PathOutput JSON
Misleading path[{"state":null}]
Corrected path[{"state":"draft"}]
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(state TEXT DEFAULT 'draft');");
      if(corrected&&i.defaultRequested)db.exec('INSERT INTO target DEFAULT VALUES');
      else db.prepare('INSERT INTO target(state) VALUES(?)').run(i.value);
      return rows(db,'SELECT * FROM target');
    }finally{db.close();}
  };
const cases=[{"label":"misleading base","input":{"defaultRequested":true,"value":null},"expected":[{"state":null}],"corrected":false},{"label":"corrected base","input":{"defaultRequested":true,"value":null},"expected":[{"state":"draft"}],"corrected":true},{"label":"intentional absent state","input":{"defaultRequested":false,"value":null},"expected":[{"state":null}],"corrected":true},{"label":"explicit supplied state","input":{"defaultRequested":false,"value":"ready"},"expected":[{"state":"ready"}],"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

An intentional null remains null. An explicit ready remains ready rather than draft.

Editable boundary records and expected outputs
CaseInput JSONExpected output JSON
Intentional null state{"defaultRequested":false,"value":null}[{"state":null}]
Explicit ready state{"defaultRequested":false,"value":"ready"}[{"state":"ready"}]
Download editable CSV ↓

Does a declared DEFAULT replace every inserted null?

Show the worked answer

No. The default applies when its value is omitted. Preserve intentional null, and omit the field only for an actual default request.

Related resources