With as使用
with as 语法:
WITH TMP AS (
select a as id from var
)
SELECT * from TMP;

问题一:
需要打开参数_t_gcluster_support_cte,gbase> show variables like '_t_gcluster_support_cte';
若没打开该参数,则会报错:
1235 (42000): This version of GBase doesn't yet support 'CTE'

打开参数后可以正常使用
set global _t_gcluster_support_cte = 1;
问题二:
打开后,使用with as结合其他语法:
WITH TMP AS (
select 'wdqw' as we
)
SELECT * from TMP;
语法还是报错:
ERROR 1149 (42000): (GBA-02SC-1001) The query includes syntax that is not supported by the gcluster.

上面语法其实是select 'wdqw' as we,单独执行这句是正常可以执行的,但是在with as中会报错,因为with as 是需要内部查询的表是需要有from的,于是修改语句后,即可使用:
WITH TMP AS (
select 'wdqw' as we from dual
)
SELECT * from TMP;
若上面语句依旧报错,报错内容:
SQL 错误 [1142][42000]: SELECT command denied to user 'test'@'localhost' for table 'dual'

报错是因为账号无dual权限,授权后即可
grant select on gclusterdb.dual to test;
热门帖子
- 12025-12-01浏览数:182764
- 22023-05-09浏览数:25062
- 42023-09-25浏览数:18526
- 52020-05-11浏览数:17529