Redshift Spectrum CTE Union
Question
I have a query with a CTE that uses a Spectrum table. When I try to union the CTE with itself:
WITH foo AS (
SELECT col1
FROM spectrum.bar
)
SELECT * FROM foo UNION ALL
SELECT * FROM foo;
I get the following error:
[XX000][500310] [Amazon](500310) Invalid operation: Relation "spectrum_foo_58abe8db83a3e" already exists Details: ----------------------------------------------- error: Relation "spectrum_foo_58abe8db83a3e" already exists code: 13 ..
Is this a known issue and/or is there any way to work around it (that doesn't involve pasting the original query for every union)?
Solution
If this can be helpful to someone, as a workaround I've created a view instead of using CTE.
CREATE VIEW foo_view AS
SELECT col1
FROM spectrum.bar
with no schema binding;
SELECT * FROM foo_view UNION ALL
SELECT * FROM foo_view;
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange