From a788a77dcb6c6625659ed2d74ee6a3b517e62e23 Mon Sep 17 00:00:00 2001 From: Bob den Os <108393871+BobdenOs@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:20:56 +0100 Subject: [PATCH] feat: use a simple select for flat queries (#324) Co-authored-by: Johannes Vogel <31311694+johannes-vogel@users.noreply.github.com> --- hana/lib/HANAService.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hana/lib/HANAService.js b/hana/lib/HANAService.js index a04417da8..0309b5d9e 100644 --- a/hana/lib/HANAService.js +++ b/hana/lib/HANAService.js @@ -144,7 +144,9 @@ class HANAService extends SQLService { }) .join(' UNION ALL ') - const ret = `DO BEGIN ${values} SELECT * FROM (${unions}) ORDER BY "_path_" ASC; END;` + const ret = temporary.length === 1 + ? `SELECT _path_ as "_path_",_blobs_ as "_blobs_",_expands_ as "_expands_",_json_ as "_json_"${blobColumns} FROM (SELECT ${temporary[0].select})` + : `DO BEGIN ${values} SELECT * FROM (${unions}) ORDER BY "_path_" ASC; END;` DEBUG?.(ret) return ret } @@ -422,7 +424,7 @@ class HANAService extends SQLService { // Making each row a maximum size of 2gb instead of the whole result set to be 2gb // Excluding binary columns as they are not supported by FOR JSON and themselves can be 2gb const rawJsonColumn = sql.length - ? `(SELECT ${sql} FROM DUMMY FOR JSON ('format'='no', 'omitnull'='no', 'arraywrap'='no') RETURNS NCLOB) AS _json_` + ? `(SELECT ${sql} FROM DUMMY FOR JSON ('format'='no', 'omitnull'='no', 'arraywrap'='no') RETURNS NVARCHAR(2147483647)) AS _json_` : `TO_NCLOB('{}') AS _json_` let jsonColumn = rawJsonColumn