Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

SQLScript: ARRAY_AGG with a string column

$
0
0

Hi all,

I'm trying to convert a table column of type NVARCHAR to an array inside a stored procedure (just as a test):

 

PROCEDURE "..."."...::test" (

  out var_out "...::simple"

  )

  LANGUAGE SQLSCRIPT

  SQL SECURITY INVOKER

  READS SQL DATA AS

BEGIN

 

  DECLARE loc NVARCHAR(20) ARRAY;

  DECLARE prod NVARCHAR(40) ARRAY;

 

 

  tab = select "LOCATIONNUMBER" as LOCATION, "PRODUCTNUMBER" as PRODUCT from "..."."ZSCP_LOCPROD";

  prod := ARRAY_AGG(:tab.PRODUCT);

  loc := ARRAY_AGG(:tab.LOCATION);

 

  var_out = unnest(:loc, :prod) as("LOCATION", "PRODUCT");

 

END;

 

When I try to activate the procedure I get the error message:

"Could not create catalog object: expression is of wrong type; Table column must be of same type than resulting array: line 16 col 19 (at pos 498)",

referring to the first ARRAY_AGG call. Does anyone have an idea what I am doing wrong?

 

 

I have already tried the same thing using other data types, like integers and dates, and it worked perfectly. Now I can't seem to be able to guess the correct syntax for string columns - unfortunately most of the examples in the SQLScript reference are with integer arrays, the only one using a VARCHAR data type is in the UNNEST section...

 

 

 

The table type of the output parameter is:

table.columns = [

   {name = "LOCATION"; sqlType = NVARCHAR; nullable = false; length = 20;},

   {name = "PRODUCT"; sqlType = NVARCHAR; nullable = false; length = 40;}

  ];

 

And the sql generating the queried table:

CREATE COLUMN TABLE "..."."ZSCP_LOCPROD" (

  "MANDT" NVARCHAR(3) DEFAULT '000' NOT NULL ,

  "LOCATIONNUMBER" NVARCHAR(20) DEFAULT '' NOT NULL ,

  "PRODUCTNUMBER" NVARCHAR(40) DEFAULT '' NOT NULL ,

  "PPLANNER" NVARCHAR(3) DEFAULT '' NOT NULL ,

  "SPLANNER" NVARCHAR(3) DEFAULT '' NOT NULL ,

  "USE" NVARCHAR(50),

  PRIMARY KEY ("MANDT",

  "LOCATIONNUMBER",

  "PRODUCTNUMBER"))


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>