Re: [SQL] Problems with default date and time

Поиск
Список
Период
Сортировка
От Patrik Kudo
Тема Re: [SQL] Problems with default date and time
Дата
Msg-id 37B425F4.DF2F4037@partitur.se
обсуждение исходный текст
Ответ на Problems with default date and time  ("Hutton, Rob" <HuttonR@plymart.com>)
Ответы Re: [SQL] Problems with default date and time  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
> "Hutton, Rob" wrote:
> 
>   I have created a table with date and time fields by using what I
> read as being the correct default statements, but I get the date and
> time the DB was created at each insert instead of the current date and
> time.
> | ord_time                         | time default text 'now'
> |     8 |
> | ord_date                         | date default text 'now'
> |     4 |
> | ord_timestamp                    | timestamp default text 'now'
> |     4 |

You should not use 'now'. It will be replaced with the current time.
Instead use now() and remove "text".

Also, I'd skip the time and date fields and exchange timestamp with
datetime. You would still be able to get the date and time from the
ord_timestamp field using:

select ord_timestamp::time, ord_timestamp::date from tablename;

The reason I'd use datetime instead of datetime is because you
can't cast from timestamp to time (afaik).

Hope this helps.

/Kudo


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Hutton, Rob"
Дата:
Сообщение: Problems with default date and time
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [SQL] Searching Text Fields - Case Sensitive?