View based on SELECT with 'WITH' clause

R. Nec picture R. Nec · Jan 12, 2015 · Viewed 15k times · Source

I've select with 'WITH' clause:

with 
alias1 as (select...),
alias2 as (select ... from alias1),
alias3 as (select col1, col2 ... from alias2)
select col1,col2 from alias3 

I tryied to create view using:

create view ex_view as (
with 
alias1 as (select...),
alias2 as (select ... from alias1),
alias3 as (select col1, col2 ... from alias2)
select col1,col2 
from alias3
)

When I tried to execute this create statement got 'unsupported use of WITH clause'

How to create view based on my select statement properely?

Answer

Gordon Linoff picture Gordon Linoff · Jan 12, 2015

Try dropping the parentheses:

create view ex_view as
with 
    alias1 as (select...),
    alias2 as (select ... from alias1),
    alias3 as (select col1, col2 ... from alias2)
from alias3;