1

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?

3
  • 2
    I love the the actual question title :) Commented Aug 29, 2018 at 2:59
  • Nitpicking: that link is not "the Postgres documentation. The official Postgres manual is here: postgresql.org/docs/current/static/index.html Commented Aug 29, 2018 at 5:29
  • What does select version() show you Commented Aug 29, 2018 at 5:30

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

If it is version I might nag about not falling too far behind on versions. I think around ver 9.6 "create table if not exists" was added which I find so useful. Upgrading is so easy and often saves a lot of grief

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.