public inbox for [email protected]  
help / color / mirror / Atom feed
Re: How to update upper-bound of tstzrange ?
3+ messages / 3 participants
[nested] [flat]

* Re: How to update upper-bound of tstzrange ?
@ 2024-05-20 11:56 Erik Wienhold <[email protected]>
  2024-05-21 10:02 ` Re: How to update upper-bound of tstzrange ? Laurenz Albe <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Erik Wienhold @ 2024-05-20 11:56 UTC (permalink / raw)
  To: Laura Smith <[email protected]>; +Cc: postgre <[email protected]>

On 2024-05-20 12:30 +0200, Laura Smith wrote:
> Could someone kindly help me out with the correct syntax ?
> 
> My first thought was the below but that doesn't work:
> 
> update foo set upper(bar_times)=upper(bar_times)+interval '1' hour where bar_id='abc';
> ERROR:  syntax error at or near "("
> LINE 1: update event_sessions set upper(bar_times)=upper(bar_ti...

Use the constructor function:

    UPDATE foo SET bar_times = tstzrange(lower(bar_times), upper(bar_times) + interval '1' hour);

But this does not preserve the inclusivity/exclusivity of bounds from
the input range, so you may have to pass in the third argument as well.

https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-CONSTRUCT

-- 
Erik






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

* Re: How to update upper-bound of tstzrange ?
  2024-05-20 11:56 Re: How to update upper-bound of tstzrange ? Erik Wienhold <[email protected]>
@ 2024-05-21 10:02 ` Laurenz Albe <[email protected]>
  2024-05-21 10:37   ` Re: How to update upper-bound of tstzrange ? Laura Smith <[email protected]>
  0 siblings, 1 reply; 3+ messages in thread

From: Laurenz Albe @ 2024-05-21 10:02 UTC (permalink / raw)
  To: Erik Wienhold <[email protected]>; Laura Smith <[email protected]>; +Cc: postgre <[email protected]>

On Mon, 2024-05-20 at 13:56 +0200, Erik Wienhold wrote:
> On 2024-05-20 12:30 +0200, Laura Smith wrote:
> > Could someone kindly help me out with the correct syntax ?
> > 
> > My first thought was the below but that doesn't work:
> > 
> > update foo set upper(bar_times)=upper(bar_times)+interval '1' hour where bar_id='abc';
> > ERROR:  syntax error at or near "("
> > LINE 1: update event_sessions set upper(bar_times)=upper(bar_ti...
> 
> Use the constructor function:
> 
>     UPDATE foo SET bar_times = tstzrange(lower(bar_times), upper(bar_times) + interval '1' hour);
> 
> But this does not preserve the inclusivity/exclusivity of bounds from
> the input range, so you may have to pass in the third argument as well.
> 
> https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-CONSTRUCT

If you need to preserve the information whether the upper and lower bounds
are inclusive or not, you could

  UPDATE foo
  SET bar_times = tstzrange(
                     lower(bar_times),
                     upper (bar_times) + INTERVAL '1 hour',
                     CASE WHEN lower_inc(bar_times) THEN '[' ELSE '(' END ||
                     CASE WHEN upper_inc(bar_times) THEN ']' ELSE ')' END
                  )
  WHERE ...

Yours,
Laurenz Albe






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

* Re: How to update upper-bound of tstzrange ?
  2024-05-20 11:56 Re: How to update upper-bound of tstzrange ? Erik Wienhold <[email protected]>
  2024-05-21 10:02 ` Re: How to update upper-bound of tstzrange ? Laurenz Albe <[email protected]>
@ 2024-05-21 10:37   ` Laura Smith <[email protected]>
  0 siblings, 0 replies; 3+ messages in thread

From: Laura Smith @ 2024-05-21 10:37 UTC (permalink / raw)
  To: postgre <[email protected]>

Thanks all for your answers !  Much appreciated.




Sent with Proton Mail secure email.

On Tuesday, 21 May 2024 at 11:02, Laurenz Albe <[email protected]> wrote:

> On Mon, 2024-05-20 at 13:56 +0200, Erik Wienhold wrote:
> 
> > On 2024-05-20 12:30 +0200, Laura Smith wrote:
> > 
> > > Could someone kindly help me out with the correct syntax ?
> > > 
> > > My first thought was the below but that doesn't work:
> > > 
> > > update foo set upper(bar_times)=upper(bar_times)+interval '1' hour where bar_id='abc';
> > > ERROR: syntax error at or near "("
> > > LINE 1: update event_sessions set upper(bar_times)=upper(bar_ti...
> > 
> > Use the constructor function:
> > 
> > UPDATE foo SET bar_times = tstzrange(lower(bar_times), upper(bar_times) + interval '1' hour);
> > 
> > But this does not preserve the inclusivity/exclusivity of bounds from
> > the input range, so you may have to pass in the third argument as well.
> > 
> > https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-CONSTRUCT
> 
> 
> If you need to preserve the information whether the upper and lower bounds
> are inclusive or not, you could
> 
> UPDATE foo
> SET bar_times = tstzrange(
> lower(bar_times),
> upper (bar_times) + INTERVAL '1 hour',
> CASE WHEN lower_inc(bar_times) THEN '[' ELSE '(' END ||
> CASE WHEN upper_inc(bar_times) THEN ']' ELSE ')' END
> )
> WHERE ...
> 
> Yours,
> Laurenz Albe






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


end of thread, other threads:[~2024-05-21 10:37 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-05-20 11:56 Re: How to update upper-bound of tstzrange ? Erik Wienhold <[email protected]>
2024-05-21 10:02 ` Laurenz Albe <[email protected]>
2024-05-21 10:37   ` Laura Smith <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox