Skip to Content
0
Sep 03, 2020 at 02:18 PM

CAP (Node.js) error when running INSERT AS SELECT queries

250 Views

I don't know where else to submit this. I'm trying to run the following query with `@sap/cds 4.1.9`

INSERT.into(MyTable).columns('column1', 'column2').as(SELECT([
	'column1',
	'column2',
	{ val: `'${now.toISOString()}'`, as: "createdAt"},
	{ val: `'anonymous'`, as: "createdBy"},
	{ val: `'${now.toISOString()}'`, as: "modifiedAt"},
	{ val: `'anonymous'`, as: "modifiedBy"}
]).from(MyOtherTable)

which results in the following error:

Exception has occurred: TypeError: Cannot convert undefined or null to object
  at Function.keys (<anonymous>)
    at checkIntegrityUtil (/home/node/app/node_modules/@sap/cds-runtime/lib/cds-services/services/utils/handlerUtils.js:207:14)
    at _performCheck (/home/node/app/node_modules/@sap/cds-runtime/lib/db/generic/integrity.js:71:9)
    ... 

The code fails because context.data is undefined here.

This used to work fine with `@sap/cds 3.x.x`