Re: A function to find errors in groups in a table

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 function to find errors in groups in a table
Date: 2022-06-09 19:16:12
Message-ID: CAJexoSJ3g9W1XtdUVnss+5cw=r-ek-JSfiGUaBxCGG=BJLmHQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Thu, Jun 9, 2022 at 6:37 AM Shaozhong SHI <shishaozhong(at)gmail(dot)com> wrote:

> There is a table full of grouped values like the following
>
> nodeid link_type primary
> 11 outflowlink 1
> 11 inflowlink 1
> 11 outflowlink 2
>
> Primary of 1 indicates a primary water course. Primary of 2 indicates a
> secondary water course.
>
> Obviously, one of the out flow links is an error, as its primacy value is
> 2. It is wrong that water flows from a primary water course into a
> secondary water course.
>
> How can a function can be designed to find and report such errors?
>

Is the problem that there exists this row:

11 outflowlink 2

But there is no corresponding row:

11 inflowlink 2

So that you need to find all "orphan" rows that don't have a corresponding
member with the opposing data field inflowlink or outflowlink where the
"primary" column is the join field between the two rows?

Thanks for clarifying your problem,
Steve

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-06-09 22:44:08 Re: cast to domain with default collation issue.
Previous Message Andreas Joseph Krogh 2022-06-09 18:58:05 Re: Logical replication of large objects

Browse pgsql-sql by date

  From Date Subject
Next Message Shaozhong SHI 2022-06-09 23:13:20 Re: A function to find errors in groups in a table
Previous Message Shaozhong SHI 2022-06-09 13:37:54 A function to find errors in groups in a table