How to ensure column names are double quoted while using execute format when building a stored procedure?

From: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: How to ensure column names are double quoted while using execute format when building a stored procedure?
Date: 2021-12-16 20:21:23
Message-ID: CA+i5JwYMbWKoJcP-o4HOY-G1YegxGs2FE0bWDanEF5g2WRj5yQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The following command runs but does not produce results as expected.

Execute Format('insert into stats select %L as id, %2$L as checks,
count(%3$s) from %4$s where %5$s is null', i, 'count of nulls in '||col,
col, t_name, col);

There should be a lot of nulls in columns, but it produces o count.

All columns have got capital letters in. How to ensure that the columns
are double-quote when they are fed in as variables.

Regards,

David

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2021-12-16 20:24:24 Re: How to ensure column names are double quoted while using execute format when building a stored procedure?
Previous Message Adrian Klaver 2021-12-16 19:42:34 Re: Packages, inner subprograms, and parameterizable anonymous blocks for PL/pgSQL