Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0oex-008RJb-5V for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 21:33:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u0oev-0059Vt-Gg for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 21:33:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0oev-0059Vl-39 for pgsql-hackers@lists.postgresql.org; Fri, 04 Apr 2025 21:33:05 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u0oet-002zG9-0k for pgsql-hackers@lists.postgresql.org; Fri, 04 Apr 2025 21:33:04 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5499e3ec54dso3010623e87.0 for ; Fri, 04 Apr 2025 14:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743802382; x=1744407182; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1T/b5pd+4CS9GQrwSKbHs+ee5aWSM+BdQEzi4f5pxLM=; b=DSpoHUSnOatml5qD+nwee6IzWSj8sPOBfQhi1QGiHn/cYxObwJ+x2ZuWrlGBfJFOg9 r+3M73zljydrXvxj1VphdldAgJsi39hLc1Ku9xhT0m+pgfqpYV4vEQNLpJhHoyZ6oIxz y0MackO9LmC/xZi3UssgaGoKupX6xc3vmPzwVVnJacnz4yUOw1YER7Tn+5ABJHkjaPDm iSP5kiJl7zX3UmD154cmmP3m/bbG3Nj+m+dDe98HBexnBn3IrAT9kmWEiL/rJwsCHutl YkOh2TiUE0ZpLMYcThHi/3EOu9fsANVwOntTHBiMgh+uIFND3xQgoMxtsofDtFqErxIo aUQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743802382; x=1744407182; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1T/b5pd+4CS9GQrwSKbHs+ee5aWSM+BdQEzi4f5pxLM=; b=I+RpwffV2lqRa6uP7YD3fY+h/LKR8NiKIl1rxl9qnS8pDbUkQduZN2C1ePkyZLRbt9 qAl5hHOo3629KSF7sV4cM1hMtAB7pGZKuDJYAxETAQlYdzRAUCfuFtVsa45lP9GAjb42 LPScwyo3cjVz6N1jM6L3FoiHmHYA+dfVU+tBZwl+hgouqmofWQg04xPr5RIiKVRs9tVt Xnz7og4OR8GVtJ3JA0hydT2UBjT0x5ohl9igGcufR8GiWTpl5/V1vkgHjqsM2lOiquXT a9pxi3geqxSQsYKrh4sgXxtzdw4ovfJlVQnayPk+qVFem4kbba5hfInZ1NxAJGoI8/tL DUqw== X-Forwarded-Encrypted: i=1; AJvYcCWCD7P5WbZwh6oIXan2e5p0U4TmS5/X/HcoJ4yn7Lit7Gl9LBRmdxSCsRfbhcjgcN3V2mUpqSQ2npvWLD6S@lists.postgresql.org X-Gm-Message-State: AOJu0YxHOFh+XnJM9fEDBwXv6OGPOrn3vovrztoTynvCGR5K7VqQOfQp 3vkxLf0Swq6IdOrOsGkusDpHbe3hKgPOgZpkSojZagV96Hnuxs/TKvktZy12xxl5YwrkVRZvuEB 5+TxKxHElbgwvQwBHT5DkbVSOyxY= X-Gm-Gg: ASbGncvNfKiZrEUHrDU3H4aUTwUk9shLlziRtMFAAXwyRDiGmPUIze2bx1fCp7pAros 80vZXnTgwlaqT0ZV/HzRehOBIcU44LprWKGWPbIUdSAE4PlIy/s4ba4D0bh6F6hLaqZmcbwbVsy ZBkLoXyv3X0M9KhyZ01PLukvsGA68= X-Google-Smtp-Source: AGHT+IGZi7heXFuCfoFaDyKW+COd5U+BdR74AFSBAKxNIVUS24xSJVTpU89cFfTxRYUnosDFwQyfEK6uh6/CmZo0DzY= X-Received: by 2002:a05:6512:10c4:b0:549:735f:f0f6 with SMTP id 2adb3069b0e04-54c2338a124mr1364767e87.50.1743802381299; Fri, 04 Apr 2025 14:33:01 -0700 (PDT) MIME-Version: 1.0 References: <90dc6e9d-9348-485a-b27c-7b1637f06c2e@uni-muenster.de> In-Reply-To: From: Masahiko Sawada Date: Fri, 4 Apr 2025 14:32:24 -0700 X-Gm-Features: ATxdqUGDt-R6O-SICuVHe0aeQZC7wwinIc5-iGu7FB9X3IndPiuyXmwE7tG3lbg Message-ID: Subject: Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row To: jian he Cc: vignesh C , Jim Jones , Kirill Reshke , Fujii Masao , "David G. Johnston" , Yugo NAGATA , torikoshia , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Apr 4, 2025 at 4:55=E2=80=AFAM jian he wrote: > > On Tue, Mar 25, 2025 at 2:31=E2=80=AFPM vignesh C w= rote: > > > > 2) Here in error we say column c1 violates not-null constraint and in > > the context we show column c2, should the context also display c2 > > column: > > postgres=3D# create table t3(c1 int not null, c2 int, check (c1 > 10)); > > CREATE TABLE > > postgres=3D# COPY t3 FROM STDIN WITH (on_error set_to_null); > > Enter data to be copied followed by a newline. > > End with a backslash and a period on a line by itself, or an EOF signal= . > > >> a b > > >> \. > > ERROR: null value in column "c1" of relation "t3" violates not-null co= nstraint > > DETAIL: Failing row contains (null, null). > > CONTEXT: COPY t3, line 1, column c2: "b" > > > > It took me a while to figure out why. > with the attached, now the error message becomes: > > ERROR: null value in column "c1" of relation "t3" violates not-null cons= traint > DETAIL: Failing row contains (null, null). > CONTEXT: COPY t3, line 1: "a,b" > > while at it, > (on_error set_to_null, log_verbosity verbose) > error message CONTEXT will only emit out relation name, > this aligns with (on_error ignore, log_verbosity verbose). > > one of the message out example: > +NOTICE: column "b" was set to null due to data type incompatibility at = line 2 > +CONTEXT: COPY t_on_error_null > > > > > 3) typo becomen should be become: > > null will becomen reserved to non-reserved > fixed. > > > 4) There is a whitespace error while applying patch > > Applying: COPY (on_error set_to_null) > > .git/rebase-apply/patch:39: trailing whitespace. > > a NOTICE message indicating the number of rows > > warning: 1 line adds whitespace errors. > fixed. I've reviewed the v15 patch and here are some comments: How about renaming the new option value to 'set_null"? The 'to' in the value name seems redundant to me. --- + COPY_ON_ERROR_NULL, /* set error field to null = */ I think it's better to rename COPY_ON_ERROR_SET_TO_NULL (or COPY_ON_ERROR_SET_NULL if we change the option value name) for consistency with the value name. --- + else if (cstate->opts.on_error =3D=3D COPY_ON_ERROR_NULL) + ereport(NOTICE, + errmsg_plural("invalid values in %" PRIu64 " row was replaced with null", + "invalid values in %" PRIu64 " rows were replaced with null", + cstate->num_errors, + cstate->num_errors)); How about adding "due to data type incompatibility" at the end of the messa= ge? --- + ereport(NOTICE, + errmsg("column \"%s\" was set to null due to data type incompatibility at line %" PRIu64 "", + cstate->cur_attname, + cstate->cur_lineno)); Similar to the IGNORE case, we can show the data in question in the message= . --- + else + ereport(ERROR, + errcode(ERRCODE_NOT_NULL_VIOLATION), + errmsg("domain %s does not allow null values", format_type_be(typioparams[m])), + errdatatype(typioparams[m])); If domain data type is the sole case where not to accept NULL, can we check it beforehand to avoid calling the second InputFunctionCallSafe() for non-domain data types? Also, if we want to end up with an error when setting NULL to a domain type with NOT NULL, I think we don't need to try to handle a soft error by passing econtext to InputFunctionCallSafe(). Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com