Re: How to select based on the condition of a column exists - Mailing list pgsql-general

From David G. Johnston
Subject Re: How to select based on the condition of a column exists
Date
Msg-id CAKFQuwZO_mVPVHiB1Nus0XzhzmG5ZL+NWVmf33sfha0HH0fxkg@mail.gmail.com
Whole thread Raw
In response to How to select based on the condition of a column exists  (Shaozhong SHI <shishaozhong@gmail.com>)
List pgsql-general
On Fri, Aug 26, 2022 at 7:01 AM Shaozhong SHI <shishaozhong@gmail.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.

pgsql-general by date:

Previous
From: Shaozhong SHI
Date:
Subject: How to select based on the condition of a column exists
Next
From: Ron
Date:
Subject: Re: Restriction on table partition expressions