Обсуждение: dates

Поиск
Список
Период
Сортировка

dates

От
John Ensign
Дата:
Hi all,

Coming from mysql, and about to lose my mind.

Dealing with yet another cms system here...

taking one field as text value and running it through to_date()...
works like a charm.

taking another text field which holds a char, casting to int4...

then trying to add the two to get another date as in:


select to_date( textfield1, 'MM-DD-YYYY') as startDate, CAST
( textfield2, int4) as duration, startDate + duration as endDate.

this doesnt work, and I can find anything concrete anywhere on it,
just sparse entries in the postgres manual posted pre 2000.  = /

ive gone through several variations on intervals and they fail as well.

its not rocket science, but im losing my mind trying to do that
should take a few seconds tops.

thanks in advance,

bob

btw db version is 7.3 and i will have to get it to work in 7.4 as well.



Вложения

Re: dates

От
Tom Lane
Дата:
John Ensign <john@deepsnow.org> writes:
> select to_date( textfield1, 'MM-DD-YYYY') as startDate, CAST
> ( textfield2, int4) as duration, startDate + duration as endDate.

That's got at least two problems: one, that's not the syntax of CAST,
you need to write CAST(textfield2 AS int4); and two, you can't reference
a SELECT output column from another column like that.  You could write

select
    to_date(textfield1, 'MM-DD-YYYY') as startDate,
    CAST(textfield2 AS int4) as duration,
    to_date(textfield1, 'MM-DD-YYYY') + CAST(textfield2 AS int4) as endDate
from whatever ...

            regards, tom lane