Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j87sB-0004Ia-1b for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Feb 2020 19:34:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j87s9-0007nQ-0A for pgsql-hackers@arkaria.postgresql.org; Sat, 29 Feb 2020 19:34:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j87s8-0007nJ-Ez for pgsql-hackers@lists.postgresql.org; Sat, 29 Feb 2020 19:34:00 +0000 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j87s1-000586-N6 for pgsql-hackers@lists.postgresql.org; Sat, 29 Feb 2020 19:33:59 +0000 Received: by mail-oi1-x244.google.com with SMTP id q81so6423965oig.0 for ; Sat, 29 Feb 2020 11:33:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=rSPHoLBeJqZmlaOfKC+GjSPv2/qfrxFpuoiEF0KLHZ0=; b=f9b0YO+91Y7m7p1OE4nGbhmeREGV404zglKl7rPRMzQj6YSw7gLAvszF9Qmg0/unv4 dMfZQ8ck+MNN12Vt8t65gf7zX0e6VgLbUaKT16YWN3q7I/zFknnkkcPGwsRfMD8cwL4L GeO/+yEd4q4V2RLWOJ3MQxRXL5CPRyOijSLhRkBtvpkk8VuoRwUx0WyfJG4bXtQAyNov Y8Ss9c3XlIwi7/bY/ZDZZpA+dqcc2atmD1oB1uYkAlgdgZb1xxmQ0FXPrDvx1JHZDSMS wGtbMM9KMAB4maHToUC4qBBGtDmrJyvMLcTyx/Pr/fdGv1/Hr41rlLlnPwj2asrnEryV NV+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=rSPHoLBeJqZmlaOfKC+GjSPv2/qfrxFpuoiEF0KLHZ0=; b=m9IdsOxp5kPxgO2KX19UCJK+SWwHuQSjCESZIBPxJao0dZd9sVHTPlPm8A1UcmbdfP 2PFim7CX9LIRM0qWwaxigQbIG/W+FZXQI08xlohKTTXtYp/JI7Da8ByM3nw5E7sS9Qr3 IDP3PNtE8LQ3iCHZC2tCxhbcsVtowdOZEHz10wdyGpUNEaElV2Mn/tv8veiQ2kK4ByLx lqoxcxDchO7j/wQPD4luz5NGF5HEcWWKLBq2vZNn4+Ngq8dtQhBuPmd+ibvs5o2eqW5F vFTj2BtHEgXBYPEdMX/9AHvaYOaO08UO//N/ub9NzKXdGtylsl+p3xQ9uWG0qerPvTJM tlcA== X-Gm-Message-State: APjAAAVYOAg+RemPWntXCp1qo7ksk2UsZVrLo+BDu0jVSeOvmcxGSW7z P8DRmAtFpQ/BY7GKZeiqLB8HJdaVvi8= X-Google-Smtp-Source: APXvYqyo/ovIiuXw4WEiLyhUlfvqtAGOzwEwt84zQgZ1pA+20Hz19VuBTNLHhvO6jc/EQCbkL9BBuA== X-Received: by 2002:aca:c490:: with SMTP id u138mr6511165oif.21.1583004832340; Sat, 29 Feb 2020 11:33:52 -0800 (PST) Received: from [100.115.92.206] (cpe-70-119-96-135.tx.res.rr.com. [70.119.96.135]) by smtp.gmail.com with ESMTPSA id a15sm3580644otf.75.2020.02.29.11.33.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 29 Feb 2020 11:33:51 -0800 (PST) To: pgsql-hackers@lists.postgresql.org From: Chris Bandy Subject: [PATCH] Add schema and table names to partition error Message-ID: <0aa113a3-3c7f-db48-bcd8-f9290b2269ae@gmail.com> Date: Sat, 29 Feb 2020 13:33:48 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------70A487A23B63871DF54DC2E8" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------70A487A23B63871DF54DC2E8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------70A487A23B63871DF54DC2E8 Content-Type: text/x-patch; charset=UTF-8; name="0001-Add-schema-and-table-names-to-partition-error.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Add-schema-and-table-names-to-partition-error.patch" From 8261b366c49b2d04baeb882d39dfa626b9315889 Mon Sep 17 00:00:00 2001 From: Chris Bandy 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.c index 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.c index 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 --------------70A487A23B63871DF54DC2E8--