pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feeddate versus datetime?
2+ messages / 2 participants
[nested] [flat]
* date versus datetime?
@ 1998-08-01 02:59 Eric McKeown <ericm@palaver.net>
0 siblings, 0 replies; 2+ messages in thread
From: Eric McKeown @ 1998-08-01 02:59 UTC (permalink / raw)
To: pgsql-sql
Hi folks,
Would anyone have any recommendations for choosing the date type versus
the datetime type for storing date information? I think the date type is
probably sufficient for my needs, and it seems a bit simpler and handier;
for instance, it seems I can do this with the date type:
select * from table where date_field < some_date_I_specify_here
However, if my reading of the manual and my experiments are correct, I
can't perform that sort of operation with the datetime type. Is my
understanding correct?
Sorry for my newbie-ness...
eric
_______________________
Eric McKeown
ericm@palaver.net
http://www.palaver.net
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: date versus datetime?
@ 1998-08-01 20:16 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 1998-08-01 20:16 UTC (permalink / raw)
To: Eric McKeown <ericm@palaver.net>; +Cc: pgsql-sql@hub.org
Eric McKeown <ericm@palaver.net> writes:
> for instance, it seems I can do this with the date type:
> select * from table where date_field < some_date_I_specify_here
> However, if my reading of the manual and my experiments are correct, I
> can't perform that sort of operation with the datetime type.
You certainly can do that with datetime; I do it all the time.
Without seeing a concrete example, I'm not sure why it's not working for
you. Perhaps you are writing the comparison date in a format that's
acceptable for type "date" but not for "datetime"? That doesn't seem
very likely though; datetime's parser is relatively flexible.
There are a couple of gotchas in writing datetime constants in SQL
commands. You have to put quotes around them (they're strings as
far as the parser is concerned). For example,
select * from ohistory where ordertime < 'jun 10 1998 16:00';
In some situations you may have to explicitly cast the string constant
to datetime type:
select * from ohistory where ordertime < 'jun 10 1998 16:00'::datetime;
but I find Postgres usually manages to figure out for itself that a
datetime value is wanted.
As far as I know those gotchas also apply to date constants, however.
So I'm still confused about why one works and not the other for you.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1998-08-01 20:16 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-08-01 02:59 date versus datetime? Eric McKeown <ericm@palaver.net>
1998-08-01 20:16 Re: date versus datetime? Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox