Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

Calculate a Year’s Chinese Zodiac Animal

Jim_KnicelyJim_Knicely Administrator
edited February 2019 in Tips from the Team

The Chinese Zodiac (Sheng Xiao) is based on a twelve-year cycle where each year is represented by an animal sign. The twelve animal signs in order are the rat, ox, tiger, rabbit, dragon, snake, horse, sheep, monkey, rooster, dog and pig. The animal sign is calculated according to the Chinese lunar calendar.

I can never remember which animal sign is used to represent the new year, so I created a simple function in Vertica to remind me!


dbadmin=> CREATE OR REPLACE FUNCTION chinese_zodiac_animal (x INT) RETURN VARCHAR(7)
dbadmin-> AS
dbadmin-> BEGIN
dbadmin->   RETURN SPLIT_PART('Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Sheep,Monkey,Rooster,Dog,Pig', ',', (((x-4)%12)::INT)+1);
dbadmin-> END;

dbadmin=> SELECT chinese_zodiac_animal(2019) "HAPPY CHINESE NEW YEAR!!!!";
(1 row)

dbadmin=> SELECT chinese_zodiac_animal(2005) "Vertica was founded in the Year of the...";
Vertica was founded in the Year of the...
(1 row)

Helpful Links:

Have fun!

Sign In or Register to comment.

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.