Skip to content
Advertisement

Presto create table with ‘with’ queries

typically to create a table in Presto (from existing db tables), I do:

create table abc as (
select...
)

But to make my code simple, I’ve broken out subqueries like this:

with sub1 as (
select...
),

sub2 as (
select...
),

sub3 as (
select...
)

select
from sub1 join sub2 on ...
          join sub3 on ...

Where do I put the create table statement here? The actual query is more complex than the above so I am trying to avoid having to put the subqueries within the main query.

Advertisement

Answer

This is possible with an INSERT INTO not sure about CREATE TABLE:

INSERT INTO s1 WITH q1 AS (...) SELECT * FROM q1

Maybe you could give this a shot:

CREATE TABLE s1 as WITH q1 AS (...) SELECT * FROM q1

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement