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

2023-03-03 Thread Alban Hertroys
> On 3 Mar 2023, at 0:02, Thorsten Glaser wrote: > > 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.) Y

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

2023-03-03 Thread cen
Likely to be safe, you'd just include both. The problem is that the query planner makes use of equivalence classes to deduce equivalence in quals. If you have a query such as: select * from t1 inner join t2 on t1.x = t2.y where t1.x = 3; then the planner can deduce that t2.y must also be 3 and

Dropping behavior for unique CONSTRAINTs

2023-03-03 Thread Conner Bean
Hi folks,I'm curious if there are any docs supporting the functionality behind dropping unique constraints. For context, I am interested in enforcing uniqueness on a column. This table is heavily used, and I plan on dropping the constraint in the future. I wanted to avoid using a unique index s

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

2023-03-03 Thread David Rowley
On Fri, 3 Mar 2023 at 22:35, cen wrote: > Does equivalency only work for constants as in the sample you provided > or will it also be found in b1."number" and t0."block_number" in my > sample query? It works for more than constants, but in this case, it's the presence of the constant that would a

PG16devel - vacuum_freeze_table_age seems not being taken into account

2023-03-03 Thread Simon Elbaz
Hi List, I am doing some tests to understand vacuum_freeze_table_age and vacuum_freeze_min_age parameters. Here is my configuration: postgres=# select name, setting from pg_settings where name = 'vacuum_freeze_min_age'; name | setting ---+- vacuum_f

Re: Dropping behavior for unique CONSTRAINTs

2023-03-03 Thread David Rowley
On Fri, 3 Mar 2023 at 23:17, Conner Bean wrote: I wanted to avoid using a unique index since dropping them requires an exclusive lock and cannot be done concurrently. My thought was to then use a unique constraint, since I've read unofficial docs[0] that say these can be dropped safely with no loc

Re: PG16devel - vacuum_freeze_table_age seems not being taken into account

2023-03-03 Thread David Rowley
On Fri, 3 Mar 2023 at 23:43, Simon Elbaz wrote: > hydrodb=# SELECT c.oid::regclass as table_name, >greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age > FROM pg_class c > LEFT JOIN pg_class t ON c.reltoastrelid = t.oid > WHERE c.relkind IN ('r', 'm') and c.relname='test'; > table_nam

Re: PG16devel - vacuum_freeze_table_age seems not being taken into account

2023-03-03 Thread Simon Elbaz
I ran vacuum without the freeze option as you can see below. Simon On Fri, Mar 3, 2023 at 12:01 PM David Rowley wrote: > On Fri, 3 Mar 2023 at 23:43, Simon Elbaz wrote: > > hydrodb=# SELECT c.oid::regclass as table_name, > >greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age > > F

Re: PG16devel - vacuum_freeze_table_age seems not being taken into account

2023-03-03 Thread Peter Geoghegan
On Fri, Mar 3, 2023 at 2:43 AM Simon Elbaz wrote: > I expected it not to be processed by vacuum freeze. > However it has been entirely frozen. > Moreover, among the 51 rows, only 1 was eligible for freeze because its XID > was older than vacuum_freeze_min_age. The effect that you noticed is a co

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

2023-03-03 Thread Thorsten Glaser
On Fri, 3 Mar 2023, Alban Hertroys wrote: >You can rewrite that into something like this: > >select jsonb_build_object('opening_times’, > obj > ORDER BY > obj->>'weekday’, > obj->>'from_hour’, > obj->>'to_hour') >) >from cot >cross join lateral jsonb_agg(j

Re: Converting row elements into a arrays?

2023-03-03 Thread Merlin Moncure
On Thu, Mar 2, 2023 at 3:47 PM Ron wrote > I'm used to the bog standard COUNT, AVG, MIN, MAX, SUM. It didn't occur to > me that there would be others... > wait until you find out you can write your own: CREATE OR REPLACE FUNCTION agg_leftagg(l TEXT, r anyelement) returns text as $$ BEGIN RETU

Re: Dropping behavior for unique CONSTRAINTs

2023-03-03 Thread Ron
On 3/3/23 04:54, David Rowley wrote: On Fri, 3 Mar 2023 at 23:17, Conner Bean wrote: I wanted to avoid using a unique index since dropping them requires an exclusive lock and cannot be done concurrently. My thought was to then use a unique constraint, since I've read unofficial docs[0] that say

Re: 13.x, stream replication and locale(?) issues

2023-03-03 Thread Thomas Munro
On Wed, Mar 1, 2023 at 10:30 AM Thomas Munro wrote: > On Wed, Mar 1, 2023 at 12:09 AM Eugene M. Zheganin wrote: > > 3) how do I fix it ? Should I take locale sources for ru_RU.utf8 on Linux > > and compile it on FreeBSD - will it help ? > > Out of curiosity (I'm not saying it's a good idea!), d

Re: Dropping behavior for unique CONSTRAINTs

2023-03-03 Thread David Rowley
On Sat, 4 Mar 2023 at 10:55, Ron wrote: > On 3/3/23 04:54, David Rowley wrote: > If you have a look at > https://www.postgresql.org/docs/15/sql-dropindex.html check out the > CONCURRENTLY option. That option allows an index to be dropped without > blocking concurrent reads and writes to the table.

Re: Converting row elements into a arrays?

2023-03-03 Thread Pavel Stehule
pá 3. 3. 2023 v 21:51 odesílatel Merlin Moncure napsal: > On Thu, Mar 2, 2023 at 3:47 PM Ron wrote > >> I'm used to the bog standard COUNT, AVG, MIN, MAX, SUM. It didn't occur >> to me that there would be others... >> > > wait until you find out you can write your own: > > CREATE OR REPLACE FUNC