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

From: Dan Kortschak <dan+pgsql(at)kortschak(dot)io>
To: Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres
Date: 2024-09-14 10:30:08
Message-ID: 48019d21fd7c669afb83161337f7e007ae619534.camel@kortschak.io
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message yudhi s 2024-09-14 10:40:15 Re: update faster way
Previous Message Alban Hertroys 2024-09-14 10:05:50 Re: re-novice coming back to pgsql: porting an SQLite update statement to postgres