Negative value in LEFT function cause error

Moderator: NorbertKrupa

Post Reply
sarah
Intermediate
Intermediate
Posts: 77
Joined: Mon Aug 27, 2012 1:34 pm

Negative value in LEFT function cause error

Post by sarah » Tue Dec 31, 2013 7:26 pm

Hello,

I have some sql code (I did not write it) that uses negative argument values in the left function. But when I run the code I get an error. Like this:

Code: Select all

dbadmin=> select left('The small pig', -3);
ERROR 4039:  Negative substring length not allowed
Is there a work around for this?

Thanks!
Have a GREAT day!

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1824
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Negative value in LEFT function cause error

Post by JimKnicely » Tue Dec 31, 2013 7:33 pm

Are you looking to get the last three characters from the string? If so, why not use the RIGHT function and a positive integer argument value?

Code: Select all

dbadmin=> select RIGHT('The small pig', 3);
 RIGHT
-------
 pig
(1 row)
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

sarah
Intermediate
Intermediate
Posts: 77
Joined: Mon Aug 27, 2012 1:34 pm

Re: Negative value in LEFT function cause error

Post by sarah » Thu Jan 02, 2014 12:58 pm

Wow... Duh! I feel dumb. Thanks, Jim. That will work for me.
Have a GREAT day!

Post Reply

Return to “Vertica SQL”