It's not only a syntax error. Vertica is relatively pecky at data types, too.
So you want to make an integer consisting of yyyymmdd
from something that looks like an ISO date.
A string?
A date?
There are two ways to go about that. You can't SUBSTR() on a date; you can't call a function getting the day, month, or year, number, from an ISO formatted string.
This example illustrates what you can do. Remember, extracting integers from dates is faster than working with strings and substrings. If your business_day
is a DATE type, do what I do with business_date
below.
Oh, and Vertica also supports this syntax:
<expression>::INTEGER
to cast to integer.
Happy playing ...
Marco
WITH
d(business_date,business_day) AS (
SELECT DATE '2018-03-04', '2018-03-04'
UNION ALL SELECT DATE '1957-04-22', '1957-04-22'
UNION ALL SELECT DATE '1959-09-27', '1959-09-27'
)
SELECT
CAST(
substr(d.business_day, 1, 4)
||substr(d.business_day, 6, 2)
||substr(d.business_day, 9, 2)
AS int
) AS with_substr
, ( YEAR (business_date)*10000
+ MONTH(business_date)*100
+ DAY (business_date)
) AS with_calc
FROM d;
with_substr|with_calc
20,180,304|20,180,304
19,570,422|19,570,422
19,590,927|19,590,927