GridDB FDW字符串比较问题:无法使用<、>运算符求协助
GridDB FDW 字符串比较问题:支持
=但无法使用</>运算符 在使用GridDB FDW连接PostgreSQL时,字符串类型字段可通过=运算符正常比较,但使用<或>运算符时会触发报错,错误信息如下:
ERROR: GridDB-API is failed by 150018 at griddb_fdw.c: 2512
Binary operation is not defined for the types STRING and STRING
测试场景
-- Prepare CREATE FOREIGN TABLE onek2 ( unique1 int4, unique2 int4, two int4, four int4, ten int4, twenty int4, hundred int4, thousand int4, twothousand int4, fivethous int4, tenthous int4, odd int4, even int4, stringu1 text, stringu2 text, string4 text ) SERVER griddb_svr; -- Scenario -- 成功执行:使用=比较字符串 explain (costs off) select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; -- 结果:Foreign Scan on onek2 select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; -- 结果:返回unique2=11的行 -- 执行报错:使用<比较字符串 explain (costs off) select * from onek2 where unique2 = 11 and stringu1 < 'B'; -- 结果:Foreign Scan on onek2 select * from onek2 where unique2 = 11 and stringu1 < 'B'; -- 错误:GridDB-API is failed by 150018 at griddb_fdw.c: 2512 -- Binary operation is not defined for the types STRING and STRING -- 同样报错:仅查询unique2字段时使用<比较 explain (costs off) select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; -- 结果:Foreign Scan on onek2 select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; -- 错误同上
可能的解决方案
禁用表达式下推,让PostgreSQL本地处理字符串比较:
修改外部表参数关闭下推,PostgreSQL会先拉取符合unique2=11的数据到本地,再执行字符串比较:ALTER FOREIGN TABLE onek2 OPTIONS (ADD disable_pushdown 'true');使用GridDB原生字符串比较函数:
利用GridDB提供的STRING_COMPARE函数替代直接运算符,函数返回-1(前者小于后者)、0(相等)、1(前者大于后者):select * from onek2 where unique2 = 11 and STRING_COMPARE(stringu1, 'B') < 0;升级GridDB FDW版本:
旧版本FDW可能未实现字符串比较运算符的下推支持,升级到最新版本可尝试解决该问题。检查GridDB表字段配置:
确认GridDB对应表的字符串字段是否设置了正确的排序规则,部分场景下需显式指定排序方式才能支持比较操作。
内容的提问来源于stack exchange,提问作者Jessica Williams
相关产品推荐
相关产品推荐

