Re: A new scenario for check constraints

From: Steve Midgley <science(at)misuse(dot)org>
To: Shaozhong SHI <shishaozhong(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: A new scenario for check constraints
Date: 2021-10-08 19:01:59
Message-ID: CAJexoSLKxRvqM72W_wqOKZb9eDiOA1t=g+SiDeXRwA9R1_0TeA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Oct 8, 2021 at 4:14 AM Shaozhong SHI <shishaozhong(at)gmail(dot)com> wrote:

> Hi, All,
>
> Can Postgres do some thing like this one?
> Checking for potential constraint violations before entering SQL Server
> TRY and CATCH logic (mssqltips.com)
> <https://www.mssqltips.com/sqlservertip/2632/checking-for-potential-constraint-violations-before-entering-sql-server-try-and-catch-logic/>
>
> The scenario is that we have a large Postgres table. Can a solution be
> designed to create a table with constraint specifications and filter in all
> records meeting specifications and producing reports (e.g., on problematic
> ones)?
>
> Your question about TRY/CATCH and your subsequent paragraph don't seem
related to me. For exception handling, I think functionally it's identical
to the MS SQL example you shared (though syntactically different):
https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

Regarding your second question, I think you just want to write some stored
procedures -- the cool thing about Pg is you can write them in almost any
language you can think of, but I believe writing them in SQL is the easiest
and with the most support/examples online:

You can create "procedures" and "functions" and to be honest I'm not
totally clear on the difference, but I know others here are:
https://www.postgresql.org/docs/current/sql-createprocedure.html

Write with specific issues you are having and the specific code you are
using, and the results you are expecting and you'll get better support.

Steve

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Karsten Hilbert 2021-10-09 18:22:26 Re: How to capture error message and save to a table in PostgreSQL?
Previous Message Steve Midgley 2021-10-08 17:09:25 Re: How to capture error message and save to a table in PostgreSQL?