pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feeddatetime query issue
4+ messages / 3 participants
[nested] [flat]
* datetime query issue
@ 1999-08-28 13:35 Frank Joerdens <frank@x9media.com>
0 siblings, 2 replies; 4+ messages in thread
From: Frank Joerdens @ 1999-08-28 13:35 UTC (permalink / raw)
To: pgsql-sql
I'm not sure how to go about this: I want to find all rows with a timestamp
between, say 6 a.m. and 10 p.m. for any number of days. The column format is
datetime. How do I extract the 'time of the day' information from this
column? What I can think of is to create a view for every single day where datetime
is > 6 and < 10 and then another query on all views together but that doesn't sound
very elegant and would be a real memory hog for a large number of days.
Any better ideas?
Thanks
Frank
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] datetime query issue
@ 1999-08-28 18:23 tjk@tksoft.com <tjk@tksoft.com>
parent: Frank Joerdens <frank@x9media.com>
1 sibling, 0 replies; 4+ messages in thread
From: tjk@tksoft.com @ 1999-08-28 18:23 UTC (permalink / raw)
To: frank@x9media.com; +Cc: pgsql-sql
Frank,
Use the date_part function to extract the hour and then
find the records which match.
E.g. select id,date_part('hour', mydate) from table1 where date_part('hour', mydate) >= 6 and date_part('hour', mydate) <= 22;
Troy
>
> I'm not sure how to go about this: I want to find all rows with a timestamp
> between, say 6 a.m. and 10 p.m. for any number of days. The column format is
> datetime. How do I extract the 'time of the day' information from this
> column? What I can think of is to create a view for every single day where datetime
> is > 6 and < 10 and then another query on all views together but that doesn't sound
> very elegant and would be a real memory hog for a large number of days.
>
> Any better ideas?
>
> Thanks
>
> Frank
>
>
> ************
>
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] datetime query issue
@ 1999-08-28 18:41 Frank Joerdens <frank@x9media.com>
parent: Frank Joerdens <frank@x9media.com>
1 sibling, 1 reply; 4+ messages in thread
From: Frank Joerdens @ 1999-08-28 18:41 UTC (permalink / raw)
To: pgsql-sql
um, this was probably unintelligible. this is the table:
+----------------------------------+----------------------------------+-------+
| Field | Type | Length|
+----------------------------------+----------------------------------+-------+
| source_numeric | int8 not null | 8 |
| destination_numeric | int8 not null | 8 |
| source | text not null | var |
| destination | text not null | var |
| bytes | int8 not null | 8 |
| date | datetime | 8 |
+----------------------------------+----------------------------------+-------+
every hour, a set of rows is added to this table with the current timestamp on
each row. i guess i need a function to extract the time from datetime. date_trunc
may be what i am looking for but i couldn't find information in the documentation
as to how to use these functions.
On Sat, Aug 28, 1999 at 03:35:07PM +0200, Frank Joerdens wrote:
> I'm not sure how to go about this: I want to find all rows with a timestamp
> between, say 6 a.m. and 10 p.m. for any number of days. The column format is
> datetime. How do I extract the 'time of the day' information from this
> column? What I can think of is to create a view for every single day where datetime
> is > 6 and < 10 and then another query on all views together but that doesn't sound
> very elegant and would be a real memory hog for a large number of days.
>
> Any better ideas?
>
> Thanks
>
> Frank
>
>
> ************
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [SQL] datetime query issue
@ 1999-08-30 13:04 José Soares <jose@sferacarta.com>
parent: Frank Joerdens <frank@x9media.com>
0 siblings, 0 replies; 4+ messages in thread
From: José Soares @ 1999-08-30 13:04 UTC (permalink / raw)
To: Frank Joerdens <frank@x9media.com>; +Cc: pgsql-sql
Try this:
select extract(year from date) from tablename;
select extract(month from date) from tablename;
select extract(day from date) from tablename;
select extract(hour from date) from tablename;
select extract(minute from date) from tablename;
select extract(minute from date) from tablename;
select extract(second from date) from tablename;
José
Frank Joerdens ha scritto:
> um, this was probably unintelligible. this is the table:
>
> +----------------------------------+----------------------------------+-------+
> | Field | Type | Length|
> +----------------------------------+----------------------------------+-------+
> | source_numeric | int8 not null | 8 |
> | destination_numeric | int8 not null | 8 |
> | source | text not null | var |
> | destination | text not null | var |
> | bytes | int8 not null | 8 |
> | date | datetime | 8 |
> +----------------------------------+----------------------------------+-------+
>
> every hour, a set of rows is added to this table with the current timestamp on
> each row. i guess i need a function to extract the time from datetime. date_trunc
> may be what i am looking for but i couldn't find information in the documentation
> as to how to use these functions.
>
> On Sat, Aug 28, 1999 at 03:35:07PM +0200, Frank Joerdens wrote:
> > I'm not sure how to go about this: I want to find all rows with a timestamp
> > between, say 6 a.m. and 10 p.m. for any number of days. The column format is
> > datetime. How do I extract the 'time of the day' information from this
> > column? What I can think of is to create a view for every single day where datetime
> > is > 6 and < 10 and then another query on all views together but that doesn't sound
> > very elegant and would be a real memory hog for a large number of days.
> >
> > Any better ideas?
> >
> > Thanks
> >
> > Frank
> >
> >
> > ************
>
> ************
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~1999-08-30 13:04 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-08-28 13:35 datetime query issue Frank Joerdens <frank@x9media.com>
1999-08-28 18:23 ` tjk@tksoft.com <tjk@tksoft.com>
1999-08-28 18:41 ` Frank Joerdens <frank@x9media.com>
1999-08-30 13:04 ` José Soares <jose@sferacarta.com>
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