Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres - Mailing list pgsql-general

From Dan Kortschak
Subject Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres
Date
Msg-id 48019d21fd7c669afb83161337f7e007ae619534.camel@kortschak.io
Whole thread Raw
In response to Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres  (Alban Hertroys <haramrae@gmail.com>)
Responses Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres
List pgsql-general
On Sat, 2024-09-14 at 12:05 +0200, Alban Hertroys wrote:
>
> That’s because the replacement data is an array of objects, not a
> single object.
>
> You need to iterate through the array elements to build your
> replacement data, something like what I do here with a select
> (because that’s way easier to play around with):
>
> with dollar6 as (
> select jsonb($$[
>                                                 {
>                                                         "data": {
> "foo": 1, "bar": 2
>                                                         },
>                                                         "end": "2023-
> 06-12T19:54:51Z",
>                                                         "start":
> "2023-06-12T19:54:39Z"
>                                                 }
>                                         ]$$::text) replacement
> )
> select *
> from dollar6
> cross join lateral jsonb_array_elements(replacement) r
> where (r->>'start')::timestamptz <= current_timestamp;


Thanks





pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres
Next
From: yudhi s
Date:
Subject: Re: update faster way