pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedInterval to number
3+ messages / 2 participants
[nested] [flat]
* Interval to number
@ 2002-05-20 11:53 Gareth Kirwan <gbjk@thermeoneurope.com>
0 siblings, 1 reply; 3+ messages in thread
From: Gareth Kirwan @ 2002-05-20 11:53 UTC (permalink / raw)
To: pgsql-admin
Postgres 7.2
I have an interval selected from a max(occurance) - min(occurance) where
bla.
I now want to multiply this by a rate - to create a charge...
If I use to_char( interval, 'SSSS');
I will get a seconds conversion - but that works on seconds since midnight -
hence
with a one day period.
Are there any better ways of converting a timestamp to an integer?
Thanks
Gareth
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Interval to number
@ 2002-05-20 16:35 Brian McCane <bmccane@mccons.net>
parent: Gareth Kirwan <gbjk@thermeoneurope.com>
0 siblings, 1 reply; 3+ messages in thread
From: Brian McCane @ 2002-05-20 16:35 UTC (permalink / raw)
To: Gareth Kirwan <gbjk@thermeoneurope.com>; +Cc: pgsql-admin
EXTRACT is your friend :)
SELECT EXTRACT(EPOCH FROM max(occurrance) - min(occurrance))::integer ;
- brian
k=# SELECT EXTRACT(EPOCH FROM now() - '2001-01-01') ;
date_part
----------------
43583467.94995
(1 row)
On Mon, 20 May 2002, Gareth Kirwan wrote:
>
> Postgres 7.2
> I have an interval selected from a max(occurance) - min(occurance) where
> bla.
> I now want to multiply this by a rate - to create a charge...
>
> If I use to_char( interval, 'SSSS');
> I will get a seconds conversion - but that works on seconds since midnight -
> hence
> with a one day period.
>
> Are there any better ways of converting a timestamp to an integer?
>
>
> Thanks
>
> Gareth
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Interval to number
@ 2002-05-20 16:40 Gareth Kirwan <gbjk@thermeoneurope.com>
parent: Brian McCane <bmccane@mccons.net>
0 siblings, 0 replies; 3+ messages in thread
From: Gareth Kirwan @ 2002-05-20 16:40 UTC (permalink / raw)
To: 'Brian McCane' <bmccane@mccons.net>; +Cc: pgsql-admin
Oh :(
I'd given up waiting for a response.
Thanks though Brian ... I currently have the triggered function:
CREATE FUNCTION logSession () RETURNS opaque AS '
DECLARE
client_rate numeric(10,2);
period interval;
to_charge numeric(10,2);
BEGIN
SELECT INTO client_rate rate from clients c where c.id=OLD.client;
SELECT INTO period max(time) - min(time) FROM convs WHERE
session_id=OLD.id;
SELECT INTO to_charge (to_number(to_char(period, ''SSSS''), ''99999D99'')
/ 60 * client_rate);
INSERT INTO previous_sessions SELECT * from current_sessions c WHERE
c.id=OLD.id;
INSERT INTO logged_convs SELECT * from convs c WHERE c.session_id=OLD.id;
INSERT INTO session_logs (session_id, time, length, charge, paid) VALUES
(OLD.id,OLD.time,period, to_charge, ''false'');
RETURN OLD;
END;'
language 'plpgsql';
So I'll try to build it into that.
-----Original Message-----
From: Brian McCane [mailto:bmccane@mccons.net]
Sent: 20 May 2002 17:35
To: Gareth Kirwan
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] Interval to number
EXTRACT is your friend :)
SELECT EXTRACT(EPOCH FROM max(occurrance) - min(occurrance))::integer ;
- brian
k=# SELECT EXTRACT(EPOCH FROM now() - '2001-01-01') ;
date_part
----------------
43583467.94995
(1 row)
On Mon, 20 May 2002, Gareth Kirwan wrote:
>
> Postgres 7.2
> I have an interval selected from a max(occurance) - min(occurance) where
> bla.
> I now want to multiply this by a rate - to create a charge...
>
> If I use to_char( interval, 'SSSS');
> I will get a seconds conversion - but that works on seconds since
midnight -
> hence
> with a one day period.
>
> Are there any better ways of converting a timestamp to an integer?
>
>
> Thanks
>
> Gareth
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid
those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-05-20 16:40 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-20 11:53 Interval to number Gareth Kirwan <gbjk@thermeoneurope.com>
2002-05-20 16:35 ` Brian McCane <bmccane@mccons.net>
2002-05-20 16:40 ` Gareth Kirwan <gbjk@thermeoneurope.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