Vertica User Defined SQL Functions Help

Moderator: NorbertKrupa

Post Reply
JimmyMac
Newbie
Newbie
Posts: 1
Joined: Wed Aug 06, 2014 7:08 pm

Vertica User Defined SQL Functions Help

Post by JimmyMac » Wed Aug 06, 2014 8:01 pm

Hi,

We are migrating from ORACLE to Vertica. In ORACLE we could do:

Select acol
from mytable
Where year = FN_GET_YEAR

And we had an ORACLE User Defined Function... (Not syntactically correct, just the main idea)

Function FN_GET_YEAR
Return varchar2
as
Begin
myyear varchar2(4);
Select MAX(Year) into myyear from YearTable;
Return myyear
END

Do I now need to recreate the FN_GET_YEAR in c++, and use it or is there a simplier way (God I hope)

Thanks so much.
-Jim

NorbertKrupa
GURU
GURU
Posts: 527
Joined: Tue Oct 22, 2013 9:36 pm
Location: Chicago, IL
Contact:

Re: Vertica User Defined SQL Functions Help

Post by NorbertKrupa » Wed Aug 06, 2014 8:16 pm

If you (for some reason) have a column for the year in your table, you can just do:

Code: Select all

SELECT [column list]
FROM table
WHERE year_column = (SELECT MAX(YEAR) FROM YearTable);
Checkout vertica.tips for more Vertica resources.

Post Reply

Return to “New to Vertica Database Development”