postgresql中的cte与ms sql
我的观察是,我们不能在postgresql中的嵌套cte案例中混合cte和递归cte,但看起来我们可以在MS SQL中这样做。我说得对吗?例如,对于postgresql,在这种情况下我将得到错误postgresql中的cte与ms sql,sql,sql-server,postgresql,tsql,common-table-expression,Sql,Sql Server,Postgresql,Tsql,Common Table Expression,我的观察是,我们不能在postgresql中的嵌套cte案例中混合cte和递归cte,但看起来我们可以在MS SQL中这样做。我说得对吗?例如,对于postgresql,在这种情况下我将得到错误 with cte1 ( ... ), recursive cte2 (...) select * from cte1 join cte2; 但看起来它适用于ms sql。这是否正确?两个数据库都支持混合使用非递归和递归公共表表达式 在Postgres中,语法为: with recursive
with cte1 ( ... ),
recursive cte2 (...)
select * from cte1 join cte2;
但看起来它适用于ms sql。这是否正确?两个数据库都支持混合使用非递归和递归公共表表达式 在Postgres中,语法为:
with recursive
cte1 as (...), -- non-recursive CTE
cte2 as (...) -- recursive CTE
select * from cte1 join cte2
SQL Server无法识别recursive
关键字,因此:
with
cte1 as (...), -- non-recursive CTE
cte2 as (...) -- recursive CTE
select * from cte1 join cte2
这两个数据库都支持混合使用非递归和递归公共表表达式 在Postgres中,语法为:
with recursive
cte1 as (...), -- non-recursive CTE
cte2 as (...) -- recursive CTE
select * from cte1 join cte2
SQL Server无法识别recursive
关键字,因此:
with
cte1 as (...), -- non-recursive CTE
cte2 as (...) -- recursive CTE
select * from cte1 join cte2
只需将
recursive
关键字放在第一个CTE之前。它适用于整个with
子句。只需将recursive
关键字放在第一个CTE之前。它适用于整个with
子句。