Re: CTE, lateral or jsonb_object_agg ?

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: CTE, lateral or jsonb_object_agg ?
Date: 2023-05-22 07:01:22
Message-ID: CAFCRh-_R6GxFm52ixS4GJPqWWA0A7XFNtYytqJoMVS0uYXOe+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, May 20, 2023 at 4:43 PM Marcos Pegoraro <marcos(at)f10(dot)com(dot)br> wrote:

> I have a table like pg_settings, so records have name and value.
>

Hi. Maybe I'm missing something, but why aren't you simply doing:

select name, varvalue from sys_var where name = any($1)

and binding your 4 (in your examples) or 10 or 1 name(s) as a text array
(i.e. text[])?
With a prepared statement you plan only once.

You can also avoid selecting names by unnest'ing the text-array with
ordinality
and join+sort on it, to get the values in name order (i.e. same order as $1
you control).
See my recent thread where I learned about that technique.

Generating SQL text dynamically when you can avoid it with proper binding
and appropriate SQL is leaving performance on the table IMHO. --DD

>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron 2023-05-22 07:08:53 Re: DBeaver postgres localhost access
Previous Message Tiffany Thang 2023-05-22 06:14:06 Re: Profiling a function call