Re: [SQL] Problems with default date and time - Mailing list pgsql-sql

From Patrik Kudo
Subject Re: [SQL] Problems with default date and time
Date
Msg-id 37B425F4.DF2F4037@partitur.se
Whole thread Raw
In response to Problems with default date and time  ("Hutton, Rob" <HuttonR@plymart.com>)
Responses Re: [SQL] Problems with default date and time
List 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 by date:

Previous
From: "Hutton, Rob"
Date:
Subject: Problems with default date and time
Next
From: Tom Lane
Date:
Subject: Re: [SQL] Searching Text Fields - Case Sensitive?