From: Chris Bandy <bandy.chris@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Subject: [PATCH] Add schema and table names to partition error
Date: Sat, 29 Feb 2020 13:33:48 -0600
Message-ID: <0aa113a3-3c7f-db48-bcd8-f9290b2269ae@gmail.com> (raw)
Hello,
I'm writing telemetry data into a table partitioned by time. When there
is no partition for a particular date, my app notices the constraint
violation, creates the partition, and retries the insert.
I'm used to handling constraint violations by observing the constraint
name in the error fields. However, this error had none. I set out to add
the name to the error field, but after a bit of reading my impression is
that partition constraints are more like a property of a table.
I've attached a patch that adds the schema and table name fields to
errors for my use case:
- Insert data into a partitioned table for which there is no partition.
- Insert data directly into an incorrect partition.
Thanks,
Chris
Attachments:
[text/x-patch] 0001-Add-schema-and-table-names-to-partition-error.patch (1.5K, ../0aa113a3-3c7f-db48-bcd8-f9290b2269ae@gmail.com/2-0001-Add-schema-and-table-names-to-partition-error.patch)
download | inline diff:
From 8261b366c49b2d04baeb882d39dfa626b9315889 Mon Sep 17 00:00:00 2001
From: Chris Bandy <bandy.chris@gmail.com>
Date: Sat, 29 Feb 2020 12:47:56 -0600
Subject: [PATCH] Add schema and table names to partition error
---
src/backend/executor/execMain.c | 3 ++-
src/backend/executor/execPartition.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git src/backend/executor/execMain.c src/backend/executor/execMain.cindex ee5c3a60ff..7cb486b211 100644--- src/backend/executor/execMain.c+++ src/backend/executor/execMain.c@@ -1878,7 +1878,8 @@ ExecPartitionCheckEmitError(ResultRelInfo *resultRelInfo,
(errcode(ERRCODE_CHECK_VIOLATION),
errmsg("new row for relation \"%s\" violates partition constraint",
RelationGetRelationName(resultRelInfo->ri_RelationDesc)),
- val_desc ? errdetail("Failing row contains %s.", val_desc) : 0));+ val_desc ? errdetail("Failing row contains %s.", val_desc) : 0,+ errtable(resultRelInfo->ri_RelationDesc)));
}
/*
diff --git src/backend/executor/execPartition.c src/backend/executor/execPartition.cindex c13b1d3501..a5542b92c7 100644--- src/backend/executor/execPartition.c+++ src/backend/executor/execPartition.c@@ -345,7 +345,8 @@ ExecFindPartition(ModifyTableState *mtstate,
RelationGetRelationName(rel)),
val_desc ?
errdetail("Partition key of the failing row contains %s.",
- val_desc) : 0));+ val_desc) : 0,+ errtable(rel)));
}
if (partdesc->is_leaf[partidx])
--
2.11.0
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: bandy.chris@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: [PATCH] Add schema and table names to partition error
In-Reply-To: <0aa113a3-3c7f-db48-bcd8-f9290b2269ae@gmail.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