M
M
mofoletta2020-03-10 18:10:45
PostgreSQL
mofoletta, 2020-03-10 18:10:45

[22007] ERROR: invalid value "{dt." for "YYYY" Details: Value must be an integer?

with
    input_vars as (
        select
            to_date(left('{dt.ToString("YYYY-MM-dd")}',10),'YYYY-MM-dd')::timestamp without time zone as m_date,
            (case when '{h}' = '8' then 8 else 10 end)  as morning_hours
    ),
    parsed_vars as (
        select
            (m_date + morning_hours * interval '1 hour') as date_start,
            (m_date + 1 * interval '1 day' + morning_hours * interval '1 hour') as date_end
        from input_vars
    )

select
(array['Понедельник','Вторник','Среда','Четверг','Пятница','Суббота','Воскресенье']) [date_part('dow',date_start)]
  || ', ' as dt,
  to_char(date_start,'DD.MM.YYYY,')  as date,


to_char(date_start, 'dd.mm.YYYY') as date_start,
to_char(date_end, 'dd.mm.YYYY') as date_end

from parsed_vars

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-03-11
@trapwalker

It looks like your SQL got a template string into which you forgot to substitute a value:
{dt.ToString("YYYY-MM-dd")}
SQL interprets this string as a regular string that you want to convert to a date using the YYYY-MM-dd. Of course, the four characters {dt.are not the four digits of the year that the pattern would expect. This is what the error is about.
The problem is not here, but a level higher, where you prepare the SQL query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question