How to perform calculations on 'time' and 'interval' datatypes

From: Marcin Bajer <bajer(at)tigana(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject: How to perform calculations on 'time' and 'interval' datatypes
Date: 2000-11-28 13:16:58
Message-ID: 3A23B04A.D861C08@tigana.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I searched the pgsql-general archives and found no answer
to my question, so I decided to ask it here.

For my acquitance-project in PostgreSQL I've chosen
kind of bus/tram timetable application

I store departures from starting terminal/stop in a table
I want to calculate departures for following stops
adding known number of minutes en route
and then store it in the table
as well.
Like: bus leaves at 4:20 goes 6 minutes to the next stop, then 10 to
another
and so on. I have only times of departure for the starting point of the
line
and want to calculate departure for all the stops.
I figured I must give the intervals in seconds for the following to
work,
but there is this problem with type mismatch

I do for example a
SELECT departure1, departure+600::intervals as departure2,
departure+1000::intervals as departure3, ...

and then departure1 is of time type, but departure2 and following are of
interval type

However, I would like them to be also of time type, so I could stuff
them in the table.
It's OK for displaying, but when I try to do an update I get
ERROR: Attribute 'departure' os of type 'time' but expression is of type
'interval'
You will need to rewrite or cast the expression.

So, casting does not work (ERROR: Cannot cast type 'time' to
'interval').
Any ideas about rewriting it?

Thanks in advance,
Marcin

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gordan Bobic 2000-11-28 13:56:11 Re: Tuple size limits and upgrading
Previous Message Igor' Robul' 2000-11-28 10:55:32 Re: Tuple size limits and upgrading