Re: [HACKERS] message for constraint

Lists: pgsql-hackerspgsql-patches
From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: message for constraint
Date: 2006-01-14 04:53:20
Message-ID: c2d9e70e0601132053o7f5a6813u35228374608c44df@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hi,

From time to time people ask me if there is a way to "customize"
messages for constraints so they could be more informative to the
user...

Imagine something like:

create table foo (fld int4 check (fld > 0));
message for constraint foo_fld_check on foo is 'fld field must contain
possitive numbers only.';

so i can let this message go directly to my users, and they can
respond without knowing waht a check constraint is...

we can use the pg_description catalog with a column added to indicate
if it is a comment or a message for constraint...

what do you think, it's worth the effort?

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jaime Casanova <systemguards(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: message for constraint
Date: 2006-01-14 09:13:47
Message-ID: 200601141013.47717.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Jaime Casanova wrote:
> From time to time people ask me if there is a way to "customize"
> messages for constraints so they could be more informative to the
> user...

What about this?

=> create table foo (fld int4 constraint "fld must contain positive numbers" check (fld > 0));
CREATE TABLE
=> insert into foo values (-5);
ERROR: new row for relation "foo" violates check constraint "fld must contain positive numbers"

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: message for constraint
Date: 2006-01-14 16:17:17
Message-ID: c2d9e70e0601140817y69d1f2dap6a0bab0e2bf849b1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On 1/14/06, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> Jaime Casanova wrote:
> > From time to time people ask me if there is a way to "customize"
> > messages for constraints so they could be more informative to the
> > user...
>
> What about this?
>
> => create table foo (fld int4 constraint "fld must contain positive numbers" check (fld > 0));
> CREATE TABLE
> => insert into foo values (-5);
> ERROR: new row for relation "foo" violates check constraint "fld must contain positive numbers"
>
> --
> Peter Eisentraut
> http://developer.postgresql.org/~petere/
>

ok, i didn't know you can use such names...

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Jaime Casanova <systemguards(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] message for constraint
Date: 2006-01-16 19:54:32
Message-ID: 200601161954.k0GJsWh19910@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I have added the following documentation addition to suggest this usage
for constraint names.

---------------------------------------------------------------------------

Jaime Casanova wrote:
> On 1/14/06, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> > Jaime Casanova wrote:
> > > From time to time people ask me if there is a way to "customize"
> > > messages for constraints so they could be more informative to the
> > > user...
> >
> > What about this?
> >
> > => create table foo (fld int4 constraint "fld must contain positive numbers" check (fld > 0));
> > CREATE TABLE
> > => insert into foo values (-5);
> > ERROR: new row for relation "foo" violates check constraint "fld must contain positive numbers"
> >
> > --
> > Peter Eisentraut
> > http://developer.postgresql.org/~petere/
> >
>
> ok, i didn't know you can use such names...
>
> --
> regards,
> Jaime Casanova
> (DBA: DataBase Aniquilator ;)
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Attachment Content-Type Size
unknown_filename text/plain 1.3 KB

From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] message for constraint
Date: 2006-01-16 20:44:25
Message-ID: c2d9e70e0601161244p159f26feld9e9960f3b3a577d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On 1/16/06, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> wrote:
>
> I have added the following documentation addition to suggest this usage
> for constraint names.
>
> ---------------------------------------------------------------------------
>
> --- 293,304 ----
> <term><literal>CONSTRAINT <replaceable class="PARAMETER">constraint_name</replaceable></literal></term>
> <listitem>
> <para>
> ! An optional name for a column or table constraint. If the
> ! constraint is violated, the constraint name is present in error messages,
> ! so constraint names like <literal>"col must be positive"</> can be used
> ! to communicate helpful constraint information to client applications.
> ! (Double-quotes are required for constraint names that contain spaces.)
> ! If not specified, the system generates a name.
> </para>
> </listitem>
> </varlistentry>
>
>

a lot better... thanx...

what about lower the context part of the messages for plpgsql
functions? that seems debug info for me... just an idea ;)

pruebas=# select prueba();
ERROR: new row for relation "foo" violates check constraint "foo_fld_check"
CONTEXT: SQL statement "insert into foo values (-1)"
PL/pgSQL function "prueba" line 2 at SQL statement

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Jaime Casanova <systemguards(at)gmail(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] message for constraint
Date: 2006-01-16 20:49:55
Message-ID: 20060116204955.GC32100@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Jaime Casanova wrote:
> On 1/16/06, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> wrote:

> what about lower the context part of the messages for plpgsql
> functions? that seems debug info for me... just an idea ;)
>
> pruebas=# select prueba();
> ERROR: new row for relation "foo" violates check constraint "foo_fld_check"
> CONTEXT: SQL statement "insert into foo values (-1)"
> PL/pgSQL function "prueba" line 2 at SQL statement

It's not debug info in the sense of the DEBUG error levels. These are
meant as debug info of the server itself, like, say, a transaction
started. The CONTEXT line is exactly that, context information.

--
Alvaro Herrera http://www.advogato.org/person/alvherre
"World domination is proceeding according to plan" (Andrew Morton)


From: Jaime Casanova <systemguards(at)gmail(dot)com>
To: Jaime Casanova <systemguards(at)gmail(dot)com>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] message for constraint
Date: 2006-01-16 20:59:45
Message-ID: c2d9e70e0601161259m6f67f0afv15cc8baabafc72f8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On 1/16/06, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> wrote:
> Jaime Casanova wrote:
> > On 1/16/06, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> wrote:
>
> > what about lower the context part of the messages for plpgsql
> > functions? that seems debug info for me... just an idea ;)
> >
> > pruebas=# select prueba();
> > ERROR: new row for relation "foo" violates check constraint "foo_fld_check"
> > CONTEXT: SQL statement "insert into foo values (-1)"
> > PL/pgSQL function "prueba" line 2 at SQL statement
>
> It's not debug info in the sense of the DEBUG error levels. These are
> meant as debug info of the server itself, like, say, a transaction
> started. The CONTEXT line is exactly that, context information.
>

ok... maybe notice? log? i suppose that the ERROR line is error level
so the idea is lowering the context so i can put
client_min_messages='error' and see just what the user can
understand...

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jaime Casanova <systemguards(at)gmail(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] message for constraint
Date: 2006-01-16 21:04:58
Message-ID: 18049.1137445498@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Jaime Casanova <systemguards(at)gmail(dot)com> writes:
> ok... maybe notice? log? i suppose that the ERROR line is error level
> so the idea is lowering the context so i can put
> client_min_messages='error' and see just what the user can
> understand...

If you don't want to show the context field, build your own error
message from the other fields. libpq provides adequate support for
that. I'm not sure what the state of play is in JDBC or other APIs,
but if you need this you should be lobbying the client-side library
authors to change, not the backend.

regards, tom lane