agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Christian Ramseyer <ramseyer@netnea.com>
To: Shaozhong SHI <shishaozhong@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: PostgreSQL CHECK Constraint
Date: Sun, 3 Oct 2021 20:47:28 +0200
Message-ID: <dd474d68-b873-e5c3-eedb-511c90ed2913@netnea.com> (raw)
In-Reply-To: <CA+i5JwbQR7kYG02LuNxfsyCcGH9YkMhdYKJ3fx78LorU-CyzLA@mail.gmail.com>
References: <CA+i5JwYC26KFQjXYBk-gNYxofhkjnWQBB-+goeusMajVdv_2_w@mail.gmail.com>
	<CA+i5Jwbo7QL+H4Q1tFV1CUQaa4ZzTLZFVwEC-YKe-bDVRsOBMA@mail.gmail.com>
	<42aaef2a-6f55-0449-5a35-d6507d333af1@netnea.com>
	<CA+i5JwbQR7kYG02LuNxfsyCcGH9YkMhdYKJ3fx78LorU-CyzLA@mail.gmail.com>

>     The reported error looks like this:
>
>     postgres@dellstore ERROR:  new row for relation "test_customers"
>     violates check constraint "check_age"
..
>
>     This errors appears in the serverlog which has many format and
>     forwarding options, you can read about them here:

On 03.10.21 20:16, Shaozhong SHI wrote:
> Hi, Christian,
> That is interesting.  Can errors be captured and saved as data with
> scripting?

Yes that works quite the same, e.g. in Python you can do

try:
    cur.execute("insert into test_customers (firstname, lastname, age)
            values ( %s, %s, %s)", ("Bobby", "Tables", 10))
except psycopg2.errors.CheckViolation as e:
    print(f"That didn't work: {e.cursor.query} failed")
    print(f"{e.pgerror}")


HTH





view thread (9+ messages)  latest in thread

Message-ID: <dd474d68-b873-e5c3-eedb-511c90ed2913@netnea.com>
Permalink:  ../dd474d68-b873-e5c3-eedb-511c90ed2913@netnea.com/
Also on:    postgresql.org/message-id/dd474d68-b873-e5c3-eedb-511c90ed2913@netnea.com

reply

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-sql@postgresql.org
  Cc: ramseyer@netnea.com, shishaozhong@gmail.com, pgsql-general@lists.postgresql.org
  Subject: Re: PostgreSQL CHECK Constraint
  In-Reply-To: <dd474d68-b873-e5c3-eedb-511c90ed2913@netnea.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox