LEFT - Remove everything before the .

Moderator: NorbertKrupa

Post Reply
stwp86
Newbie
Newbie
Posts: 11
Joined: Mon Nov 12, 2012 7:06 pm

LEFT - Remove everything before the .

Post by stwp86 » Thu Mar 21, 2013 4:12 pm

Anyone know how this snippet would translate in to Vertica SQL . . . seems to not like CHARINDEX.

Code: Select all

LEFT(Column1, CHARINDEX('.', Column1) - 1)
Thanks!

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

Re: LEFT - Remove everything before the .

Post by JimKnicely » Thu Mar 21, 2013 6:06 pm

Hi,

In MS SQL Server:

Image

In Vertica, you can try the INSTR function or the POSITION function:

Code: Select all

dbadmin=> SELECT INSTR('Vertica. is cool', '.'),
dbadmin->        POSITION('.' IN 'Vertica. is cool');
 INSTR | position
-------+----------
     8 |        8
(1 row)
So including the LEFT function, you could do one of the following:

Code: Select all

dbadmin=> SELECT LEFT('Vertica. is cool', INSTR('Vertica. is cool', '.') - 1),
dbadmin->        LEFT('Vertica. is cool', POSITION('.' IN 'Vertica. is cool') - 1);
  LEFT   |  LEFT
---------+---------
 Vertica | Vertica
(1 row)
I hope this helps!
Jim Knicely

Image

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

stwp86
Newbie
Newbie
Posts: 11
Joined: Mon Nov 12, 2012 7:06 pm

Re: LEFT - Remove everything before the .

Post by stwp86 » Fri Mar 22, 2013 7:50 pm

Thank you!

I also came across this method . . .

Code: Select all

split_part(column1, '.', 1)

Post Reply

Return to “Vertica SQL”