pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to store in hours:minutes:seconds where hours may be bigger than 24
7+ messages / 5 participants
[nested] [flat]

* How to store in hours:minutes:seconds where hours may be bigger than 24
@ 2024-03-20 02:05  Celia McInnis <celia.mcinnis@gmail.com>
  0 siblings, 2 replies; 7+ messages in thread

From: Celia McInnis @ 2024-03-20 02:05 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi:

I want to store times in a database as hours:minutes:seconds where hours
can be greater than 24. How do I do this? I will want to be able to add
such times.

Thanks,
Celia McInnis

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

* Re: How to store in hours:minutes:seconds where hours may be bigger than 24
@ 2024-03-20 02:34  Ron Johnson <ronljohnsonjr@gmail.com>
  parent: Celia McInnis <celia.mcinnis@gmail.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Ron Johnson @ 2024-03-20 02:34 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On Tue, Mar 19, 2024 at 10:05 PM Celia McInnis <celia.mcinnis@gmail.com>
wrote:

> Hi:
>
> I want to store times in a database as hours:minutes:seconds where hours
> can be greater than 24. How do I do this? I will want to be able to add
> such times.
>

Try the INTERVAL data type.

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

* Re: How to store in hours:minutes:seconds where hours may be bigger than 24
@ 2024-03-20 02:44  Steve Baldwin <steve.baldwin@gmail.com>
  parent: Celia McInnis <celia.mcinnis@gmail.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Steve Baldwin @ 2024-03-20 02:44 UTC (permalink / raw)
  To: Celia McInnis <celia.mcinnis@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Could you use an interval data type? For example:

b2bcreditonline=# create table interval_example (i interval);
CREATE TABLE
b2bcreditonline=# insert into interval_example values
('26:15:32'::interval);
INSERT 0 1
b2bcreditonline=# select * from interval_example;
    i
----------
 26:15:32
(1 row)

b2bcreditonline=# select i, i + interval '45 minutes' as plus from
interval_example;
    i     |   plus
----------+----------
 26:15:32 | 27:00:32
(1 row)

Steve

On Wed, Mar 20, 2024 at 1:05 PM Celia McInnis <celia.mcinnis@gmail.com>
wrote:

> Hi:
>
> I want to store times in a database as hours:minutes:seconds where hours
> can be greater than 24. How do I do this? I will want to be able to add
> such times.
>
> Thanks,
> Celia McInnis
>

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

* Re: How to store in hours:minutes:seconds where hours may be bigger than 24
@ 2024-03-20 02:56  Celia McInnis <celia.mcinnis@gmail.com>
  parent: Steve Baldwin <steve.baldwin@gmail.com>
  0 siblings, 2 replies; 7+ messages in thread

From: Celia McInnis @ 2024-03-20 02:56 UTC (permalink / raw)
  To: Steve Baldwin <steve.baldwin@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Thanks for the suggestion, Steve, but No - when I insert 25:17:07::interval
into my table I get 01:17:07 into the table - i.e., it replaces 25 hours by
(25 mod 24) hours or 1 hour, and this is not what I want. I really need the
number of hours rather than the number of hours mod 24. Do I have to make a
composite type to get what I want???

Thanks,
Celia McInnis

On Tue, Mar 19, 2024 at 10:44 PM Steve Baldwin <steve.baldwin@gmail.com>
wrote:

> Could you use an interval data type? For example:
>
> b2bcreditonline=# create table interval_example (i interval);
> CREATE TABLE
> b2bcreditonline=# insert into interval_example values
> ('26:15:32'::interval);
> INSERT 0 1
> b2bcreditonline=# select * from interval_example;
>     i
> ----------
>  26:15:32
> (1 row)
>
> b2bcreditonline=# select i, i + interval '45 minutes' as plus from
> interval_example;
>     i     |   plus
> ----------+----------
>  26:15:32 | 27:00:32
> (1 row)
>
> Steve
>
> On Wed, Mar 20, 2024 at 1:05 PM Celia McInnis <celia.mcinnis@gmail.com>
> wrote:
>
>> Hi:
>>
>> I want to store times in a database as hours:minutes:seconds where hours
>> can be greater than 24. How do I do this? I will want to be able to add
>> such times.
>>
>> Thanks,
>> Celia McInnis
>>
>

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

* Re: How to store in hours:minutes:seconds where hours may be bigger than 24
@ 2024-03-20 03:01  Christophe Pettus <xof@thebuild.com>
  parent: Celia McInnis <celia.mcinnis@gmail.com>
  1 sibling, 1 reply; 7+ messages in thread

From: Christophe Pettus @ 2024-03-20 03:01 UTC (permalink / raw)
  To: Celia McInnis <celia.mcinnis@gmail.com>; +Cc: Steve Baldwin <steve.baldwin@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>



> On Mar 19, 2024, at 19:56, Celia McInnis <celia.mcinnis@gmail.com> wrote:
> 
> Thanks for the suggestion, Steve, but No - when I insert 25:17:07::interval into my table I get 01:17:07 into the table - i.e., it replaces 25 hours by (25 mod 24) hours or 1 hour, and this is not what I want. I really need the number of hours rather than the number of hours mod 24. Do I have to make a composite type to get what I want???

I'm not seeing that result:

xof=# create table t (i interval);
CREATE TABLE
xof=# insert into t values('25:17:07'::interval);
INSERT 0 1
xof=# select * from t;
    i     
----------
 25:17:07
(1 row)

Can you show what you are doing that gets the result you describe?




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

* Re: How to store in hours:minutes:seconds where hours may be bigger than 24
@ 2024-03-20 03:02  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Celia McInnis <celia.mcinnis@gmail.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Tom Lane @ 2024-03-20 03:02 UTC (permalink / raw)
  To: Celia McInnis <celia.mcinnis@gmail.com>; +Cc: Steve Baldwin <steve.baldwin@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Celia McInnis <celia.mcinnis@gmail.com> writes:
> Thanks for the suggestion, Steve, but No - when I insert 25:17:07::interval
> into my table I get 01:17:07 into the table - i.e., it replaces 25 hours by
> (25 mod 24) hours or 1 hour, and this is not what I want.

There is definitely something you are not telling us, because it
works in isolation:

regression=# create table t (f1 interval);
CREATE TABLE
regression=# insert into t values ('25:17:07'::interval);
INSERT 0 1
regression=# select * from t;
    f1    
----------
 25:17:07
(1 row)

What's the full context of your problem?

			regards, tom lane





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

* Re: How to store in hours:minutes:seconds where hours may be bigger than 24
@ 2024-03-20 03:07  Celia McInnis <celia.mcinnis@gmail.com>
  parent: Christophe Pettus <xof@thebuild.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Celia McInnis @ 2024-03-20 03:07 UTC (permalink / raw)
  To: Christophe Pettus <xof@thebuild.com>; +Cc: Steve Baldwin <steve.baldwin@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Whoops - I hadn't changed the type of the column in the table that I was
inserting into - it was of type "TIME WITHOUT TIMEZONE". Now that I have
set the column type to INTERVAL, I can insert the string '25:17:07' into
the column without even needing to do any casting.

Thank goodness and thanks!
Celia

On Tue, Mar 19, 2024 at 11:01 PM Christophe Pettus <xof@thebuild.com> wrote:

>
>
> > On Mar 19, 2024, at 19:56, Celia McInnis <celia.mcinnis@gmail.com>
> wrote:
> >
> > Thanks for the suggestion, Steve, but No - when I insert
> 25:17:07::interval into my table I get 01:17:07 into the table - i.e., it
> replaces 25 hours by (25 mod 24) hours or 1 hour, and this is not what I
> want. I really need the number of hours rather than the number of hours mod
> 24. Do I have to make a composite type to get what I want???
>
> I'm not seeing that result:
>
> xof=# create table t (i interval);
> CREATE TABLE
> xof=# insert into t values('25:17:07'::interval);
> INSERT 0 1
> xof=# select * from t;
>     i
> ----------
>  25:17:07
> (1 row)
>
> Can you show what you are doing that gets the result you describe?

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


end of thread, other threads:[~2024-03-20 03:07 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-20 02:05 How to store in hours:minutes:seconds where hours may be bigger than 24 Celia McInnis <celia.mcinnis@gmail.com>
2024-03-20 02:34 ` Ron Johnson <ronljohnsonjr@gmail.com>
2024-03-20 02:44 ` Steve Baldwin <steve.baldwin@gmail.com>
2024-03-20 02:56   ` Celia McInnis <celia.mcinnis@gmail.com>
2024-03-20 03:01     ` Christophe Pettus <xof@thebuild.com>
2024-03-20 03:07       ` Celia McInnis <celia.mcinnis@gmail.com>
2024-03-20 03:02     ` 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