Re: Conditional INSERT

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Conditional INSERT
Date: 2019-03-15 20:02:29
Message-ID: 94fb335b-4a63-b0e3-3168-83f3b57da26e@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Am 15.03.19 um 18:55 schrieb basti:
> Hello,
>
> I want to insert data into table only if condition is true.
> For example:
>
> INSERT into mytable (domainid, hostname, txtdata)
> VALUES (100,'_acme.challenge.example', 'somedata');
>
> The insert should only be done if Hostname like %_acme.challenge%.
>
>

you can use a check-constraint:

create table mytable(hostname text, check(hostname like
'%_acme.challenge%'));

I think you can see the idea...

Regards, Andreas

--
2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Morris de Oryx 2019-03-15 22:43:06 Re: Camel case identifiers and folding
Previous Message Chapman Flack 2019-03-15 19:26:50 Re: Facing issue in using special characters