WITH Clause in SELECT with empty result set
Hi,
I am trying to use the WITH clause in a SELECT. Documentation is at https://my.vertica.com/docs/7.0.x/HTML/index.htm#Authoring/ProgrammersGuide/Queries/WITHClausesInSELECT.htm .
My query looks like this.
WITH
with_clause_1 AS (SELECT ... ),
with_clause_2 AS (SELECT ... )
SELECT *
FROM with_clause_1, with_clause_2
If both *with_clauses* return values, then the query works fine. However, if one of them do not have any rows (e.g. with_clause_1 returns 0 row), then the result of the whole query returns zero row.
Does anyone know how I can write the query such that rows will always be returned if at least 1 of the clauses return a row? For the clauses that return 0 row, it's ok to return a static value too, so something like NULL is fine to indicate 0 row returned.
Is this a bug with this WITH clause then?
Comments
I just found a workaround by doing a UNION with DUAL, but it requires defining a specific value for each column in the query. It would still be nice to not have to do this.
Actually, the UNION with DUAL will only address the case where one of the *with_clauses* return an empy result set. But if the with_clause has values, I'm not gettingn the same result set as running the whole query vs. running the "select for the with_clause UNION DUAL".
Also, I don't understand why the WITH clause is used in this case then if you're just doing a union. Alternative, you can just have a union for all those selects in the with_clauses. The only "advantage" I see is that you get to use these named queries in the union.
I will update if there are any other issues.
Thanks id10t for pointing me in the right direction.