pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: JITEN KUMAR SHAH <jitenshah78@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Creating constraint dynamically
Date: Mon, 22 Aug 2022 13:53:35 +0530
Message-ID: <7af57a5d-459d-0533-2541-7a181fc9c274@GMAIL.COM> (raw)
In-Reply-To: <ed85aadf60bea6dc30b1d6f1733fb6fd927492d6.camel@ucll.be>
References: <129838278.823301.1661153341365.ref@mail.yahoo.com>
	<129838278.823301.1661153341365@mail.yahoo.com>
	<ed85aadf60bea6dc30b1d6f1733fb6fd927492d6.camel@ucll.be>



On 8/22/22 13:09, Wim Bertels wrote:
> sivapostgres@yahoo.com schreef op ma 22-08-2022 om 07:29 [+0000]:
>> ALTER TABLE public.tx_barcode_stock
>> ADD CONSTRAINT "tx_barcode_stock_CK1" CHECK
>> ( (branchcode = '1'::bpchar  and barcodeitem = 'Y'::bpchar and
>> closingstock >= 0::numeric)  Or (branchcode = '1' and barcodeitem =
>> 'N'::bpchar and closingstock >= 0::numeric )  Or (branchcode =
>> '2'::bpchar  and barcodeitem = 'Y'::bpchar and closingstock >=
>> 0::numeric)  Or (branchcode = '2' and  barcodeitem = 'N'::bpchar and
>> closingstock >= 0::numeric ) ) NOT VALID;
>>
>> After creation, when we check what we find is  [ in PgAdmin ]
>> ALTER TABLE public.tx_barcode_stock
>>      ADD CONSTRAINT "tx_barcode_stock_CK1" CHECK (branchcode::bpchar =
>> '1'::bpchar AND barcodeitem = 'Y'::bpchar AND closingstock >=
>> 0::numeric OR branchcode::text = '1'::text AND barcodeitem =
>> 'N'::bpchar AND closingstock >= 0::numeric OR branchcode::bpchar =
>> '2'::bpchar AND barcodeitem = 'Y'::bpchar AND closingstock >=
>> 0::numeric OR branchcode::text = '2'::text AND barcodeitem =
>> 'N'::bpchar AND closingstock >= 0::numeric)
>>      NOT VALID;
>>
>> We have only one bracket, in the final updated one.
>>
>> Since there are AND and OR conditions, without brackets the whole
>> conditions becomes useless.
> did you see
> https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE
> ?
>
>
> mvg,
> Wim

You can use plpgsql function
alter table tale_name add constraint xyz  check (func(table_name))






view thread (6+ messages)  latest in thread

Message-ID: <7af57a5d-459d-0533-2541-7a181fc9c274@GMAIL.COM>
Permalink:  ../7af57a5d-459d-0533-2541-7a181fc9c274@GMAIL.COM/
Also on:    postgresql.org/message-id/7af57a5d-459d-0533-2541-7a181fc9c274@GMAIL.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: jitenshah78@gmail.com
  Subject: Re: Creating constraint dynamically
  In-Reply-To: <7af57a5d-459d-0533-2541-7a181fc9c274@GMAIL.COM>
  References: <129838278.823301.1661153341365.ref@mail.yahoo.com> <129838278.823301.1661153341365@mail.yahoo.com> <ed85aadf60bea6dc30b1d6f1733fb6fd927492d6.camel@ucll.be> <7af57a5d-459d-0533-2541-7a181fc9c274@GMAIL.COM>

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

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