pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Group by minute
4+ messages / 4 participants
[nested] [flat]

* Group by minute
@ 2006-09-22 13:52  Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  0 siblings, 3 replies; 4+ messages in thread

From: Ezequias Rodrigues da Rocha @ 2006-09-22 13:52 UTC (permalink / raw)
  To: pgsql-sql

Hil list,

I have a query but my IDE (Delphi) does not accept "to_char" capability. Is
there a way to reproduce the same query without using to_char function ?

Here is my query:
SELECT  to_char(quando,'dd/MM/yyyy HH24:MI'),count(id)
FROM base.tentativa
WHERE  (SESSAO_ID = 15)
GROUP BY to_char(quando,'dd/MM/yyyy HH24:MI')
order by 1

Regards ...

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                  Atenciosamente (Sincerely)
                        Ezequias Rodrigues da Rocha
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
A pior das democracias ainda é melhor do que a melhor das ditaduras
The worst of democracies is still better than the better of dictatorships
http://ezequiasrocha.blogspot.com/

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Group by minute
@ 2006-09-22 14:10  Niklas Johansson <spot@tele2.se>
  parent: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Niklas Johansson @ 2006-09-22 14:10 UTC (permalink / raw)
  To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql


On 22 sep 2006, at 15.52, Ezequias Rodrigues da Rocha wrote:
> I have a query but my IDE (Delphi) does not accept "to_char"  
> capability. Is there a way to reproduce the same query without  
> using to_char function ?
>
> ...
> GROUP BY to_char(quando,'dd/MM/yyyy HH24:MI')

To group by minute, you can try

GROUP BY date_trunc('minute', quando)

or even

GROUP BY EXTRACT(EPOCH FROM quando)::integer / 60


Sincerely,

Niklas Johansson






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Group by minute
@ 2006-09-22 14:14  Mezei Zoltán <mezei.zoltan@telefor.hu>
  parent: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Mezei Zoltán @ 2006-09-22 14:14 UTC (permalink / raw)
  To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000099">
Ezequias Rodrigues da Rocha wrote:
<blockquote
 cite="mid55c095e90609220652t356c8591u412046aed091a52f@mail.gmail.com"
 type="cite">Hil list,<br>
  <br>
I have a query but my IDE (Delphi) does not accept "to_char"
capability. Is there a way to reproduce the same query without using
to_char function ?<br>
  <br>
Here is my query:<br>
SELECT  to_char(quando,'dd/MM/yyyy HH24:MI'),count(id)
  <br>
FROM base.tentativa<br>
WHERE  (SESSAO_ID = 15) <br>
GROUP BY to_char(quando,'dd/MM/yyyy HH24:MI')<br>
order by 1<br>
  <br>
</blockquote>
That seems like a valid query in Oracle :-)<br>
<br>
Postgres have a slightly different mechanism for handling date and
time. The modified query:<br>
<br>
SELECT  date_trunc('minute', quando),count(id)
<br>
FROM base.tentativa<br>
WHERE  (SESSAO_ID = 15) <br>
-- GROUP BY to_char(quando,'dd/MM/yyyy HH24:MI')<br>
GROUP BY date_trunc('minute', quando)<br>
order by 1<br>
<br>
You should read:<br>
<a class="moz-txt-link-freetext" href="http://www.postgresql.org/docs/8.1/interactive/functions-datetime.html">http://www.postgresql...;
<br>
Zizi<br>
</body>
</html>



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Group by minute
@ 2006-09-22 14:56  Scott Marlowe <smarlowe@g2switchworks.com>
  parent: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Scott Marlowe @ 2006-09-22 14:56 UTC (permalink / raw)
  To: Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>; +Cc: pgsql-sql

On Fri, 2006-09-22 at 10:52 -0300, Ezequias Rodrigues da Rocha wrote:
> Hil list,
> 
> I have a query but my IDE (Delphi) does not accept "to_char"
> capability. Is there a way to reproduce the same query without using
> to_char function ?
> 
> Here is my query:
> SELECT  to_char(quando,'dd/MM/yyyy HH24:MI'),count(id) 
> FROM base.tentativa
> WHERE  (SESSAO_ID = 15) 
> GROUP BY to_char(quando,'dd/MM/yyyy HH24:MI')
> order by 1
> 

Assuming that your IDE has the same issues with date_trunc, you could
always put things into a view...

in psql do something like:

create view frozen_caveman_ide as 
	SELECT to_char(quando,'dd/MM/yyyy HH24:MI'),
		count(id) FROM base.tentativa 
	GROUP BY to_char(quando,'dd/MM/yyyy HH24:MI');

then just call the view when you need that.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2006-09-22 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-09-22 13:52 Group by minute Ezequias Rodrigues da Rocha <ezequias.rocha@gmail.com>
2006-09-22 14:10 ` Niklas Johansson <spot@tele2.se>
2006-09-22 14:14 ` Mezei Zoltán <mezei.zoltan@telefor.hu>
2006-09-22 14:56 ` Scott Marlowe <smarlowe@g2switchworks.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