Can't convert to date!

Moderator: NorbertKrupa

Post Reply
User avatar
Josh
Intermediate
Intermediate
Posts: 106
Joined: Thu Jan 26, 2012 9:38 pm

Can't convert to date!

Post by Josh » Fri Jun 13, 2014 1:32 pm

This is driving me crazy! What am I doing wrong? :shock:

Code: Select all

dbadmin=> select to_date(20140613, 'YYYYMMDD');
ERROR 3457:  Function to_date(int, unknown) does not exist, or permission is denied for to_date(int, unknown)
HINT:  No function matches the given name and argument types. You may need to add explicit type casts
That is a valid date!
Thank you!
Joshua

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

Re: Can't convert to date!

Post by JimKnicely » Fri Jun 13, 2014 2:06 pm

The TO_DATE function only accepts VARCHARs as input parameters:

Code: Select all

dbadmin=> \df to_date
                         List of functions
 procedure_name | procedure_return_type | procedure_argument_types
----------------+-----------------------+--------------------------
 to_date        | Date                  | Varchar, Varchar
(1 row)
Try converting your INT to a VARCHAR:

Code: Select all

dbadmin=> SELECT TO_DATE(20140613::VARCHAR(8), 'YYYYMMDD') AS "Friday the 13th!";
 Friday the 13th!
------------------
 2014-06-13
(1 row)
Jim Knicely

Image

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

User avatar
Josh
Intermediate
Intermediate
Posts: 106
Joined: Thu Jan 26, 2012 9:38 pm

Re: Can't convert to date!

Post by Josh » Fri Jun 13, 2014 3:11 pm

Arghhhhh! :evil: Thanks, Jim! That was what I was missing...
Thank you!
Joshua

Post Reply

Return to “Vertica SQL”