pgsql: Improve error messages about misuse of SELECT INTO.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improve error messages about misuse of SELECT INTO.
Date: 2021-08-21 14:22:24
Message-ID: E1mHRtA-0005e6-Gd@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Improve error messages about misuse of SELECT INTO.

Improve two places in plpgsql, and one in spi.c, where an error
message would confusingly tell you that you couldn't use a SELECT
query, when what you had written *was* a SELECT query. The actual
problem is that you can't use SELECT ... INTO in these contexts,
but the messages failed to make that apparent. Special-case
SELECT INTO to make these errors more helpful.

Also, fix the same spots in plpgsql, as well as several messages
in exec_eval_expr(), to not quote the entire complained-of query or
expression in the primary error message. That behavior very easily
led to violating our message style guideline about keeping the primary
error message short and single-line. Also, since the important part
of the message was after the inserted text, it could make the real
problem very hard to see. We can report the query or expression as
the first line of errcontext instead.

Per complaint from Roger Mason. Back-patch to v14, since (a) some
of these messages are new in v14 and (b) v14's translatable strings
are still somewhat in flux. The problem's older than that of
course, but I'm hesitant to change the behavior further back.

Discussion: https://postgr.es/m/1914708.1629474624@sss.pgh.pa.us

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8f6a52196aceb11a78eb1d673a03ab3ab72da231

Modified Files
--------------
src/backend/executor/spi.c | 10 ++++-
src/pl/plpgsql/src/expected/plpgsql_array.out | 5 ++-
src/pl/plpgsql/src/pl_exec.c | 53 ++++++++++++++++++++-------
3 files changed, 51 insertions(+), 17 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2021-08-22 11:31:35 pgsql: Allow parallel DISTINCT
Previous Message Dilip Kumar 2021-08-21 12:38:17 Re: pgsql: pgstat: Bring up pgstat in BaseInit() to fix uninitialized use o