11-02-2021 07:46 PM
11-03-2021 12:08 AM
In the CTE you can't do a CREATE.
It expects an expression in the form of expression_name [ ( column_name [ , ... ] ) ] [ AS ] ( query )
where expression_name specifies a name for the common table expression.
If you want to create a view from a CTE, you can do this:
-- CTE in CREATE VIEW statement
CREATE VIEW v AS
WITH t(a, b, c, d) AS (SELECT 1, 2, 3, 4)
SELECT * FROM t;
SELECT * FROM v;
+---+---+---+---+
| a| b| c| d|
+---+---+---+---+
| 1| 2| 3| 4|
+---+---+---+---+
PS. snippet from the Spark documentation
11-02-2021 11:26 PM
Hi @Constantine! My name is Kaniz, and I'm the technical moderator here. Great to meet you, and thanks for your question! Let's see if your peers in the community have an answer to your question first. Or else I will get back to you soon. Thanks.
11-03-2021 12:08 AM
In the CTE you can't do a CREATE.
It expects an expression in the form of expression_name [ ( column_name [ , ... ] ) ] [ AS ] ( query )
where expression_name specifies a name for the common table expression.
If you want to create a view from a CTE, you can do this:
-- CTE in CREATE VIEW statement
CREATE VIEW v AS
WITH t(a, b, c, d) AS (SELECT 1, 2, 3, 4)
SELECT * FROM t;
SELECT * FROM v;
+---+---+---+---+
| a| b| c| d|
+---+---+---+---+
| 1| 2| 3| 4|
+---+---+---+---+
PS. snippet from the Spark documentation
03-21-2024 10:55 AM
Just want to say that you for replying to this. Just spent hours trying to figure out why my query wasn't working and this did the trick.
Excited to expand your horizons with us? Click here to Register and begin your journey to success!
Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!