Re: PostgreSQL CHECK Constraint

Поиск
Список
Период
Сортировка
От Christian Ramseyer
Тема Re: PostgreSQL CHECK Constraint
Дата
Msg-id dd474d68-b873-e5c3-eedb-511c90ed2913@netnea.com
обсуждение исходный текст
Ответ на Re: PostgreSQL CHECK Constraint  (Shaozhong SHI <shishaozhong@gmail.com>)
Ответы Re: PostgreSQL CHECK Constraint  (Shaozhong SHI <shishaozhong@gmail.com>)
Список pgsql-general
>     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



В списке pgsql-general по дате отправления:

Предыдущее
От: Shaozhong SHI
Дата:
Сообщение: Re: PostgreSQL CHECK Constraint
Следующее
От: Shaozhong SHI
Дата:
Сообщение: Re: PostgreSQL CHECK Constraint