From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Shaozhong SHI <shishaozhong(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: How to select based on the condition of a column exists |
Date: | 2022-08-26 14:05:26 |
Message-ID: | CAKFQuwZO_mVPVHiB1Nus0XzhzmG5ZL+NWVmf33sfha0HH0fxkg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Aug 26, 2022 at 7:01 AM Shaozhong SHI <shishaozhong(at)gmail(dot)com>
wrote:
> The following does not work.
> select count(test) from table where exists (select test from table)
>
>
> How to select based on the condition of a column exists? It column test
> is not exists, a message need to be returned.
>
>
You have to query the system catalog (or information schema) for the
absence of an expected row. Otherwise the only message you will end up
returning is "column not found" since you cannot write and execute an SQL
query without knowing and defining its entire structure.
Alternatively, you write a function with an exception block.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Ron | 2022-08-26 14:47:52 | Re: Restriction on table partition expressions |
Previous Message | Shaozhong SHI | 2022-08-26 14:01:27 | How to select based on the condition of a column exists |