Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?

2023-03-02 Thread David Rowley
On Fri, 3 Mar 2023 at 02:20, cen wrote: > I understand that even though both colums are indexed, the indexes are > completely different but the point is, how would one know in advance > which one will be faster when designing the query? Likely to be safe, you'd just include both. The problem is t

Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?

2023-03-02 Thread Kirk Wolak
On Thu, Mar 2, 2023 at 8:20 AM cen wrote: > On 16/02/2023 17:15, Ron wrote: > > On 2/16/23 09:47, cen wrote: > >> Hi, > >> > >> I am running the same application (identical codebase) as two > >> separate instances to index (save) different sets of data. Both run > >> PostgreSQL 13. > >> > >> The

Re: DISTINCT *and* ORDER BY in aggregate functions on expressions(!)y

2023-03-02 Thread Thorsten Glaser
On Tue, 28 Feb 2023, Alban Hertroys wrote: >Perhaps you can use a lateral cross join to get the result of >jsonb_build_object as a jsonb value to pass around? I don’t see how. (But then I’ve not yet worked with lateral JOINs.) But I c̲a̲n̲ just generate the objects first, I t̲h̲i̲n̲k̲, given one

Re: Converting row elements into a arrays?

2023-03-02 Thread Rob Sargent
On 3/2/23 14:49, Ron wrote: On 3/2/23 15:45, Rob Sargent wrote: On 3/2/23 13:58, Ron wrote: Postgresql 12.13 Given the sample below, I'm looking for how to generate this output.  It's like GROUP BY, but generating an array instead of an aggreate number.  f1 | f2_array +- 1 | {1,

Re: Converting row elements into a arrays?

2023-03-02 Thread Ron
On 3/2/23 15:01, Ray O'Donnell wrote: On 02/03/2023 20:58, Ron wrote: Postgresql 12.13 Given the sample below, I'm looking for how to generate this output.  It's like GROUP BY, but generating an array instead of an aggreate number.   f1 | f2_array +- 1 | {1,2,3}    2 | {1,2,3,4}  

Re: Converting row elements into a arrays?

2023-03-02 Thread Ron
On 3/2/23 15:45, Rob Sargent wrote: On 3/2/23 13:58, Ron wrote: Postgresql 12.13 Given the sample below, I'm looking for how to generate this output.  It's like GROUP BY, but generating an array instead of an aggreate number.  f1 | f2_array +- 1 | {1,2,3}   2 | {1,2,3,4}   3 | {1,

Re: Converting row elements into a arrays?

2023-03-02 Thread Ron
On 3/2/23 15:34, David G. Johnston wrote: On Thu, Mar 2, 2023 at 1:58 PM Ron wrote: Postgresql 12.13 Given the sample below, I'm looking for how to generate this output.  It's like GROUP BY, but generating an array instead of an aggreate number. Group By creates groups, that'

Re: Converting row elements into a arrays?

2023-03-02 Thread Rob Sargent
On 3/2/23 13:58, Ron wrote: Postgresql 12.13 Given the sample below, I'm looking for how to generate this output.  It's like GROUP BY, but generating an array instead of an aggreate number.  f1 | f2_array +- 1 | {1,2,3}   2 | {1,2,3,4}   3 | {1,2} The ultimate goal is to somehow

Re: Converting row elements into a arrays?

2023-03-02 Thread David G. Johnston
On Thu, Mar 2, 2023 at 1:58 PM Ron wrote: > Postgresql 12.13 > > Given the sample below, I'm looking for how to generate this output. It's > like GROUP BY, but generating an array instead of an aggreate number. > > Group By creates groups, that's it. How you aggregate the data that are in those

Re: Converting row elements into a arrays?

2023-03-02 Thread Ray O'Donnell
On 02/03/2023 21:01, Ray O'Donnell wrote: On 02/03/2023 20:58, Ron wrote: Postgresql 12.13 Given the sample below, I'm looking for how to generate this output. It's like GROUP BY, but generating an array instead of an aggreate number.   f1 | f2_array +- 1 | {1,2,3}    2 | {1,2,3,

Re: Converting row elements into a arrays?

2023-03-02 Thread Ray O'Donnell
On 02/03/2023 20:58, Ron wrote: Postgresql 12.13 Given the sample below, I'm looking for how to generate this output. It's like GROUP BY, but generating an array instead of an aggreate number.  f1 | f2_array +- 1 | {1,2,3}   2 | {1,2,3,4}   3 | {1,2} Something like this (off

Converting row elements into a arrays?

2023-03-02 Thread Ron
Postgresql 12.13 Given the sample below, I'm looking for how to generate this output.  It's like GROUP BY, but generating an array instead of an aggreate number.  f1 | f2_array +- 1 | {1,2,3}   2 | {1,2,3,4}   3 | {1,2} The ultimate goal is to somehow use pg_index.indkey to get col

Re: Postgres undeterministically uses a bad plan, how to convince it otherwise?

2023-03-02 Thread cen
On 16/02/2023 17:15, Ron wrote: On 2/16/23 09:47, cen wrote: Hi, I am running the same application (identical codebase) as two separate instances to index (save) different sets of data. Both run PostgreSQL 13. The queries are the same but the content in actual databases is different. One

Re: Getting the exact SQL from inside an event trigger

2023-03-02 Thread Joe Wildish
Hi Depesz, On Thu, 2 Mar 2023, at 12:29, hubert depesz lubaczewski wrote: > This might be a bit different answer from what you expect, but have you > seen pgl_ddl_deploy project? Thanks --- I was unaware of this project so I will take a look. However, we are operating under a limitation that the

Re: Getting the exact SQL from inside an event trigger

2023-03-02 Thread hubert depesz lubaczewski
On Thu, Mar 02, 2023 at 11:12:37AM +, Joe Wildish wrote: > We are using event triggers to capture DDL for subsequent replay on a logical > replica. This might be a bit different answer from what you expect, but have you seen pgl_ddl_deploy project? Best regards, depesz

Getting the exact SQL from inside an event trigger

2023-03-02 Thread Joe Wildish
Hello all, We are using event triggers to capture DDL for subsequent replay on a logical replica. The intention is to write the DDL statement to a table, inside the same transaction that executes the DDL, and have a separate process on the replica notice changes in this table and execute whate

Re: Postgres Index and Updates

2023-03-02 Thread Dominique Devienne
On Thu, Mar 2, 2023 at 10:08 AM Laurenz Albe wrote: > On Thu, 2023-03-02 at 15:53 +0800, Navindren Baskaran wrote: > If the other column is updated, it depends. If the updated column is not > indexed and there is enough room for the new row version in the same > table block, the index doesn't ha

Re: Postgres Index and Updates

2023-03-02 Thread Laurenz Albe
On Thu, 2023-03-02 at 15:53 +0800, Navindren Baskaran wrote: > We would like to understand in which scenario an index on a table will be > rebuilt. I assume that you are meaning "updated" or "modified" rather than rebuilt from scratch. > Example if we have a table, which has two columns and one

Re: Failed upgrade from 12.11 to 14.4

2023-03-02 Thread Arthur Ramsey
I was unaware this was a user created view. Dropping the view did the trick thanks for the help. On Wed, Mar 1, 2023 at 1:54 PM Tom Lane wrote: > Arthur Ramsey writes: > > "Database instance is in a state that cannot be upgraded: pg_restore: > from > > TOC entry 1264; 1259 32392758 VIEW pg_sta