<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Problem with HANA JSON_TABLE() function in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426296#M4652335</link>
    <description>&lt;P&gt;I am using an instance of the SAP HANA Cloud service, in my SAP BTP Trial account.&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;txnData&lt;/EM&gt; variable is of type &lt;STRONG&gt;NCLOB&lt;/STRONG&gt; (to be able to support large JSONs).&lt;/P&gt;</description>
    <pubDate>Mon, 06 Sep 2021 00:52:34 GMT</pubDate>
    <dc:creator>iperez-sofos</dc:creator>
    <dc:date>2021-09-06T00:52:34Z</dc:date>
    <item>
      <title>Problem with HANA JSON_TABLE() function</title>
      <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaq-p/12426292</link>
      <description>&lt;P&gt;Greetings.&lt;/P&gt;
  &lt;P&gt;I am using the &lt;STRONG&gt;JSON_TABLE()&lt;/STRONG&gt; function inside a stored procedure that I am writing.&lt;/P&gt;
  &lt;P&gt;The JSON data has a non-trivial structure, below I leave the expression that I am using exactly. &lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt; -- "flatten" transaction data
 lt_flatTxnData = SELECT JT.idxNameID, JT.idxName, JT.idxDescr, JT.idxClass, JT.idxMeasUnit,
                         JT.idxStage, JT.maxStdDev, JT.idxRelative, JT.refNameID, JT.breed,
                         JT.gender, JT.season, JT.refBasVal, JT.refN, JT.refDayNum, JT.refFac,
                         JT.refFacAcum, JT.refStdDev, JT.histNameID, JT.housingUn, JT.histBasVal,
                         JT.histN, JT.histDayNum, JT.histFac, JT.histFacAcum, JT.histStdDev
                    FROM JSON_TABLE(:txnData, '$'
                             COLUMNS
                             (
                                 idxNameID NVARCHAR(111) PATH '$.nameID',
                                 idxName NVARCHAR(111) PATH '$.name',
                                 idxDescr NVARCHAR(1111) PATH '$.descr',
                                 idxClass NVARCHAR(111) PATH '$.idxClass_item',
                                 idxMeasUnit NVARCHAR(111) PATH '$.measUnit_ID',
                                 idxStage NVARCHAR(36) PATH '$.stage_ID',
                                 maxStdDev DOUBLE PATH '$.maxStdDev',
                                 idxRelative NVARCHAR(10) PATH '$.isRelative',
                                 NESTED PATH '$.curves'
                                 COLUMNS
                                 (
                                     refNameID NVARCHAR(111) PATH '$.nameID',
                                     breed NVARCHAR(36) PATH '$.breed_ID',
                                     gender NVARCHAR(111) PATH '$.gender_item',
                                     season NVARCHAR(36) PATH '$.season_ID',
                                     refBasVal DOUBLE PATH '$.baseValue',
                                     refN INTEGER PATH '$.n',
                                     NESTED PATH '$.dataPoints'
                                     COLUMNS
                                     (
                                         refDayNum INTEGER PATH '$.dayNum',
                                         refFac DOUBLE PATH '$.f',
                                         refFacAcum DOUBLE PATH '$.fAcum',
                                         refStdDev DOUBLE PATH '$.stdDev'
                                     ),
                                     NESTED PATH '$.historicCurves'
                                     COLUMNS
                                     (
                                         histNameID NVARCHAR(111) PATH '$.nameID',
                                         housingUn NVARCHAR(36) PATH '$.housingUnit_unit_ID',
                                         histBasVal DOUBLE PATH '$.baseValue',
                                         histN INTEGER PATH '$.n',
                                         NESTED PATH '$.dataPoints'
                                         COLUMNS
                                         (
                                             histDayNum INTEGER PATH '$.dayNum',
                                             histFac DOUBLE PATH '$.f',
                                             histFacAcum DOUBLE PATH '$.fAcum',
                                             histStdDev DOUBLE PATH '$.stdDev'
                                         )
                                     )
                                 )
                             )
                         ) AS JT; &lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;My goal (my initial intention) is to put all the JSON dataset into a temporary table (many people call this "flattening" the data), and then, using the temporary table, extract three different pieces of the data to insert into three different tables; one table for the top-level columns, another table for the &lt;EM&gt;&lt;STRONG&gt;'$ .curves'&lt;/STRONG&gt;&lt;/EM&gt; section, and another table for the &lt;EM&gt;'&lt;STRONG&gt;$.historicCurves'&lt;/STRONG&gt;&lt;/EM&gt; section.&lt;/P&gt;
  &lt;P&gt;Something that makes the requirement more complicated is that the &lt;STRONG&gt;&lt;EM&gt;'$ .curves'&lt;/EM&gt;&lt;/STRONG&gt; and &lt;STRONG&gt;&lt;EM&gt;'$ .historicCurves'&lt;/EM&gt;&lt;/STRONG&gt; sections are optional, so these may or may not be in the JSON data.&lt;/P&gt;
  &lt;P&gt;Regarding this last requirement comes my main question:&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;Is it possible to do what I am looking for or does the JSON_TABLE function not allow it (that is, optional sections)?&lt;/STRONG&gt; (I have already checked the documentation for the JSON_TABLE function in &lt;A href="https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.04/en-US/f8f6916b5c434a6fbd1bb7e0dc65acd4.html" target="test_blank"&gt;https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.04/en-US/f8f6916b5c434a6fbd1bb7e0dc65acd4.html&lt;/A&gt;, but I don't know if I have misunderstood something.).&lt;/P&gt;
  &lt;P&gt;The code I put in earlier has no compilation errors, but at the moment it generates a run-time error when the optional sections are missing: &lt;/P&gt;
  &lt;P&gt;"error": {&lt;/P&gt;
  &lt;P&gt; "code": 339,&lt;/P&gt;
  &lt;P&gt; "message": "invalid number: &amp;lt;ErrorPath&amp;gt;: invalid nested path expression"&lt;/P&gt;
  &lt;P&gt;}&lt;/P&gt;
  &lt;P&gt;With that error message, I wonder if something is missing in my JSON_TABLE expression (or if something is wrong)&lt;/P&gt;
  &lt;P&gt;Thank you very much in advance for any help and/or suggestions.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 23:24:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaq-p/12426292</guid>
      <dc:creator>iperez-sofos</dc:creator>
      <dc:date>2021-09-03T23:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with HANA JSON_TABLE() function</title>
      <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426293#M4652332</link>
      <description>&lt;P&gt;Do you have an example of such a JSON which you can share.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 05:37:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426293#M4652332</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2021-09-05T05:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with HANA JSON_TABLE() function</title>
      <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426294#M4652333</link>
      <description>&lt;P&gt;For sure yes, &lt;SPAN class="mention-scrubbed"&gt;florian.pfeffer&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;I am attaching an example JSON that I am using to test the stored procedure that I am writing (maybe you can notice that the two sections &lt;STRONG&gt;'$ .dataPoints'&lt;/STRONG&gt; have the same set of values; that is just for ease for me when building this example, in real scenarios it doesn't have to be like this).&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 05:49:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426294#M4652333</guid>
      <dc:creator>iperez-sofos</dc:creator>
      <dc:date>2021-09-05T05:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with HANA JSON_TABLE() function</title>
      <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426295#M4652334</link>
      <description>&lt;P&gt;What HANA version you are using?&lt;/P&gt;&lt;P&gt;And what type of kind has variable txnData?&lt;/P&gt;&lt;P&gt;I tested it on HANA Cloud with a NVARCHAR typed variable and got a result (without the error you described).&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 08:08:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426295#M4652334</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2021-09-05T08:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with HANA JSON_TABLE() function</title>
      <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426296#M4652335</link>
      <description>&lt;P&gt;I am using an instance of the SAP HANA Cloud service, in my SAP BTP Trial account.&lt;/P&gt;&lt;P&gt;The &lt;EM&gt;txnData&lt;/EM&gt; variable is of type &lt;STRONG&gt;NCLOB&lt;/STRONG&gt; (to be able to support large JSONs).&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 00:52:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426296#M4652335</guid>
      <dc:creator>iperez-sofos</dc:creator>
      <dc:date>2021-09-06T00:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with HANA JSON_TABLE() function</title>
      <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426297#M4652336</link>
      <description>&lt;P&gt;I do not get an error with nclob type too. Compared to your code if have not made an adjustment in the statement which uses JSON_TABLE. Just txnData is declared with type nclob and the json example you provided (I removed all not necessary flags, new lines and carriage returns in the JSON data).&lt;/P&gt;</description>
      <pubDate>Mon, 06 Sep 2021 06:42:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426297#M4652336</guid>
      <dc:creator>pfefferf</dc:creator>
      <dc:date>2021-09-06T06:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with HANA JSON_TABLE() function</title>
      <link>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426298#M4652337</link>
      <description>&lt;P&gt;Hello Isaac,&lt;/P&gt;&lt;P&gt;have you ever fixed the problem? &lt;/P&gt;&lt;P&gt;was it because of the optional entries in &lt;EM&gt;'$ .curves'&lt;/EM&gt; and &lt;EM&gt;'$ .historicCurves'?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;best regards,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Alex&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 18:57:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/problem-with-hana-json-table-function/qaa-p/12426298#M4652337</guid>
      <dc:creator>seitz_alex</dc:creator>
      <dc:date>2022-05-31T18:57:00Z</dc:date>
    </item>
  </channel>
</rss>

