Skip to content

Problem with SQLite on INSERT.into...from when providing columns #1559

Description

@MartinStenzig

Problem description

Based on the model in model.cds I am trying to perform a simple...

const result = await INSERT.into(e2).from(SELECT.columns('ID','description').from(e1))

... but then get this error

SqliteError: no such column: value in:
INSERT INTO ao_test_T_ReportingTypes (ID,description,sourceSystem,createdAt,createdBy,modifiedAt,modifiedBy) SELECT NEW.ID AS ID,NEW.description AS description,(CASE WHEN json_type(value,'$."sourceSystem"') IS NULL THEN 'local' ELSE NULL END) AS sourceSystem,(CASE WHEN json_type(value,'$."createdAt"') IS NULL THEN ISO(session_context('$now')) ELSE ISO(NULL) END) AS createdAt,(CASE WHEN json_type(value,'$."createdBy"') IS NULL THEN session_context('$user.id') ELSE NULL END) AS createdBy,(CASE WHEN json_type(value,'$."modifiedAt"') IS NULL THEN ISO(session_context('$now')) ELSE ISO(NULL) END) AS modifiedAt,(CASE WHEN json_type(value,'$."modifiedBy"') IS NULL THEN session_context('$user.id') ELSE NULL END) AS modifiedBy FROM (SELECT "$S".ID,"$S".description FROM ao_test_S_ReportingTypes as "$S") AS NEW

The problem seems to be somewhere in the data model I used in combination with the implementation as if I use a simpler data model like the following...

namespace ao.test;

entity s_asset {
    key ID          : UUID;
        name        : String(255);
        description : String(255);
}


entity t_asset {
    key ID          : UUID;
        name        : String(255);
        description : String(255);
}

...it works.

Detailed steps to reproduce

see GitHub repo: https://github.com/MartinStenzig/cds-bug-12

Details about your project

Package Version Location
@sap/cds-dk (global) 9.8.2 /usr/local/lib/node_modules/@sap/cds-dk
@sap/cds 9.8.4 ./node_modules/@sap/cds
@sap/cds-compiler 6.8.0 ./node_modules/@sap/cds-compiler
@sap/cds-fiori 2.3.0 ./node_modules/@sap/cds-fiori
@cap-js/db-service 2.9.0 ./node_modules/@cap-js/db-service
@cap-js/sqlite 2.2.0 ./node_modules/@cap-js/sqlite
cds.home ./node_modules/@sap/cds
cds.root ~/dev/MartinStenzig/cds-bug-12
npm root -l ./node_modules
npm root -g /usr/local/lib/node_modules
Node.js 24.13.1 /usr/local/bin/node

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcqn2sqlcqn-to-sql transformation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions