RIGHT() function in Postgres is not right

问题: I'm reviewing the Postgres RIGHT() function documentation, right.. For the documentation example: SELECT RIGHT('XYZ', 2); I was expecting the right response as per t...

问题:

I'm reviewing the Postgres RIGHT() function documentation, right..

For the documentation example:

SELECT RIGHT('XYZ', 2);

I was expecting the right response as per the documentation viz;

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

But then I ran the query in Aginity Workbench and the result wasn't right. I get:

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

Can someone set me right?


回答1:

The right function is only available beginning with Postgres version 9.1. I am guessing that the version used which generated that error message is using version 9.0 or earlier.

See the documentation for 9.0 which does not have a right function, then see the documentation for 9.1 which shows that right is available.

As a workaround, you may use substr:

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

World
  • 发表于 2018-09-02 11:13
  • 阅读 ( 336 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除