- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2021 07:46 PM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

