Skip to content
Astera Technology

Why did a table copy put a name into the count column?

Name destination columns when the source and target layouts differ.

Download complete case notes and answer keys ↓

Read the source and its declared rule

This original source stores name then integer count; target stores count then name and a default tag. A positional INSERT SELECT follows destination order and places A into count,2 into name. The corrected copy names name, count explicitly and lets tag use its declared default.

Filled synthetic input
RecordInput JSON
Base input{"name":"A","count":2}
Download editable CSV ↓

Compare the actual paths

Both inserts can finish in this non-STRICT target, so absence of an error is insufficient. Inspect actual typed destination values: corrected count 2/nameA/tag new.

Misleading and corrected outputs
PathOutput JSON
Misleading path[{"count":"A","name":"2","tag":"new"}]
Corrected path[{"count":2,"name":"A","tag":"new"}]
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 source(name TEXT,count INTEGER);CREATE TABLE target(count INTEGER,name TEXT,tag TEXT DEFAULT 'new');");
      db.prepare('INSERT INTO source VALUES(?,?)').run(i.name,i.count);
      if(corrected)db.exec('INSERT INTO target(name,count) SELECT name,count FROM source');
      else db.exec("INSERT INTO target SELECT name,count,'new' FROM source");
      return rows(db,'SELECT * FROM target');
    }finally{db.close();}
  };
const cases=[{"label":"misleading base","input":{"name":"A","count":2},"expected":[{"count":"A","name":"2","tag":"new"}],"corrected":false},{"label":"corrected base","input":{"name":"A","count":2},"expected":[{"count":2,"name":"A","tag":"new"}],"corrected":true},{"label":"zero quantity remains zero","input":{"name":"A","count":0},"expected":[{"count":0,"name":"A","tag":"new"}],"corrected":true},{"label":"empty permitted display name","input":{"name":"","count":2},"expected":[{"count":2,"name":"","tag":"new"}],"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

Zero count and an allowed empty display name keep their intended columns and values.

Editable boundary records and expected outputs
CaseInput JSONExpected output JSON
Recorded zero quantity{"name":"A","count":0}[{"count":0,"name":"A","tag":"new"}]
Allowed empty display name{"name":"","count":2}[{"count":2,"name":"","tag":"new"}]
Download editable CSV ↓

Does successful positional insertion prove the fields were mapped correctly?

Show the worked answer

No. The bad row contains countA/name 2. Use named destinations; the correct row has count 2/nameA.

Related resources

System integration services →