RE: [SQL] Problems with default date and time
RE: [SQL] Problems with default date and time
sorry, Here's the create statement.
CREATE TABLE "orders" (
"ord_id" int4 DEFAULT nextval ( 'next_ord_id' ) NOT NULL,
"req_id" int4 DEFAULT nextval ( 'next_req_id' ) NOT NULL,
"ord_description" character varying(1500),
"ord_priority" character varying(1500),
"ord_pri_order" int4,
"ord_time" time DEFAULT now(),
"ord_date" date DEFAULT now(),
"ord_timestamp" datetime DEFAULT now(),
"ord_tech" character varying(1500),
"ord_stat" character varying(2),
"ord_notes" character varying(1500),
"ord_whse" int4);-----Original Message-----
From: Hutton, Rob
Sent: Friday, August 13, 1999 10:25 AM
To: 'Patrik Kudo'; Hutton, Rob
Cc: 'pgsql-sql@postgresql.org'
Subject: RE: [SQL] Problems with default date and timeThe time and date fields are for reporting purposes while the timestamp is for calculating elapsed time, so I need all of them. When I make those changes, I get:
ERROR: DEFAULT clause type 'timestamp' mismatched with column type 'time'
-----Original Message-----
From: Patrik Kudo [mailto:kudo@partitur.se]
Sent: Friday, August 13, 1999 10:05 AM
To: Hutton, Rob
Cc: 'pgsql-sql@postgresql.org'
Subject: Re: [SQL] Problems with default date and time> "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
Re: [SQL] Problems with default date and time
Sorry... I couldn't get the ord_time and ord_date fields working either. =/ Will the ord_time/date/timestamp ever differ from eachother? If not, I think you'll still be able to do what you want to do even after removing the time and date fields as these can be fetched from the timestamp field. /Kudo > > -----Original Message----- > From: Hutton, Rob > Sent: Friday, August 13, 1999 10:25 AM > To: 'Patrik Kudo'; Hutton, Rob > Cc: 'pgsql-sql@postgresql.org' > Subject: RE: [SQL] Problems with default date and time > > The time and date fields are for reporting purposes while the > timestamp is for calculating elapsed time, so I need all of them. > When I make those changes, I get: > > ERROR: DEFAULT clause type 'timestamp' mismatched with column type > 'time' >