CTAS with OPENJSON

Vanya Strelchenko 51 Reputation points
2023-02-21T18:35:49.42+00:00

Hello Microsoft team,
I am using dedicated sql pool with COMPATIBILITY_LEVEL set to 130. CTAS and OPENJSON queries work fine when executed separately. However, something weird happens when I try to run CTAS statement with a SELECT query that uses OPENJSON function. When I run the script below I get the following error: Parse error at line: 4, column: 18: Incorrect syntax near 'AS'. There is nothing wrong with the syntax, but for some mysterious reason the CTAS operation fails. Could you please help me figure out what is going on?

DECLARE @array VARCHAR(MAX);
SET @array = '[{"month":"Jan", "temp":10},{"month":"Feb", "temp":12},{"month":"Mar", "temp":15},
               {"month":"Apr", "temp":17},{"month":"May", "temp":23},{"month":"Jun", "temp":27}
              ]';

CREATE TABLE [dbo].[Months]
WITH (
    DISTRIBUTION = ROUND_ROBIN,
    HEAP
) 
AS
SELECT * 
FROM OPENJSON(@array)
        WITH (  
            month VARCHAR(3),
            temp int
            ) as months;
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,112 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. x-Koszegi, Robert 0 Reputation points
    2024-04-19T09:33:00.3933333+00:00

    I have the same problem. Create view works though.

    0 comments No comments