From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Replace run-time error check with assertion
Date: Tue, 25 May 2021 11:28:56 +0200
Message-ID: <452e9df8-ec89-e01b-b64a-8cc6ce830458@enterprisedb.com> (raw)
In the attached patch, the error message was checking that the
structures returned from the parser matched expectations. That's
something we usually use assertions for, not a full user-facing error
message. So I replaced that with an assertion (hidden inside
lfirst_node()).
Attachments:0001-Replace-run-time-error-check-with-assertion.patch (text/plain, 1.7K) download
From a30697758c475db2f4333cedbe6aad1e1acd0ee8 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 25 May 2021 11:27:04 +0200
Subject: [PATCH] Replace run-time error check with assertion
The error message was checking that the structures returned from the
parser matched expectations. That's something we usually use
assertions for, not a full user-facing error message.
---
src/backend/commands/statscmds.c | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.cindex acae19176c..b244a0fbd7 100644--- a/src/backend/commands/statscmds.c+++ b/src/backend/commands/statscmds.c@@ -220,26 +220,14 @@ CreateStatistics(CreateStatsStmt *stmt)
*/
foreach(cell, stmt->exprs)
{
- Node *expr = (Node *) lfirst(cell);- StatsElem *selem;- HeapTuple atttuple;- Form_pg_attribute attForm;- TypeCacheEntry *type;-- /*- * We should not get anything else than StatsElem, given the grammar.- * But let's keep it as a safety.- */- if (!IsA(expr, StatsElem))- ereport(ERROR,- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),- errmsg("only simple column references and expressions are allowed in CREATE STATISTICS")));-- selem = (StatsElem *) expr;+ StatsElem *selem = lfirst_node(StatsElem, cell);
if (selem->name) /* column reference */
{
char *attname;
+ HeapTuple atttuple;+ Form_pg_attribute attForm;+ TypeCacheEntry *type;
attname = selem->name;
@@ -273,6 +261,7 @@ CreateStatistics(CreateStatsStmt *stmt)
{
Node *expr = selem->expr;
Oid atttype;
+ TypeCacheEntry *type;
Assert(expr != NULL);
--
2.31.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: peter.eisentraut@enterprisedb.com
Subject: Re: Replace run-time error check with assertion
In-Reply-To: <452e9df8-ec89-e01b-b64a-8cc6ce830458@enterprisedb.com>
References: <452e9df8-ec89-e01b-b64a-8cc6ce830458@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox