Postgres 中的 RIGHT() 函数不正确

RIGHT() function in Postgres is not right

我正在查看 Postgres RIGHT() function documentation,对..

对于文档示例:

SELECT RIGHT('XYZ', 2);

我期待根据文档得到正确的回应;

 right
-------
 YZ
(1 row)

但后来我 运行 在 Aginity Workbench 中查询,结果不正确。我得到:

found "RIGHT" (at char 8) expecting an identifier found a keyword

有人可以纠正我吗?

right 函数仅从 Postgres 版本 9.1 开始可用。我猜测生成该错误消息的版本使用的是 9.0 或更早版本。

查看 documentation for 9.0 which does not have a right function, then see the documentation for 9.1,其中显示 right 可用。

作为解决方法,您可以使用 substr:

select
    substr('Hello World', char_length('Hello World') - 4, 5);

World