0

I can't find any information if I can reference outside table column while trying to convert JSON data in a table format.

An example:

-- create temp table for data

create local temporary table #test("StorageId" INT, "Items" nvarchar(200));

-- insert 1 test data

insert into #test("StorageId", "Items")
values(1, '[22,33]');

-- query used for converting the json data to table where im passing the json column from the outside table

SELECT e."StorageId"
FROM #test AS e
where 22 in (
        select "ItemId" from JSON_TABLE(e."Items", '$[*]' COLUMNS ("ItemId" INT PATH '$'))
    )

And this query returns error:

(dberror) [259]: invalid table name: table does not exist > E:

If I put the array string instead of the outside table column then the query executes:

select e."StorageId"
from #test AS e
where 22 in (
        select "ItemId" from JSON_TABLE('[22,33]', '$[*]' COLUMNS ("ItemId" INT PATH '$'))
    )   

1 Answer 1

1

Seems like the alias e is not know in the inner scope. You can instead use the full table reference:

SELECT e."StorageId"
FROM #test AS e
where 22 in (
        select "ItemId" from JSON_TABLE(#test."Items", '$[*]' COLUMNS ("ItemId" INT PATH '$'))
    )

If you are working with SAP HANA Cloud, I'd encourage to take a look at its JSON Document Store as it offers performant filtering by array elements even for large data volumes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.