GBase 8a
运维管理
文章

With as使用

发表于2026-04-16 17:42:4915次浏览3个评论

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;

评论

登录后才可以发表评论
曾云林发表于 2个月前
三人行必有我师
shepherd发表于 2个月前
来了
xinyiedc!发表于 2个月前
谢谢分享