Re: How to include/reference a common bit of code in a function - Mailing list pgsql-novice

From Laurenz Albe
Subject Re: How to include/reference a common bit of code in a function
Date
Msg-id 1529563883.2488.2.camel@cybertec.at
Whole thread Raw
In response to How to include/reference a common bit of code in a function  ("chandru.aroor@yahoo.com" <chandru.aroor@yahoo.com>)
List pgsql-novice
chandru.aroor@yahoo.com wrote:
> I have a function that has multiple UNION ALLs. As part of the WHERE condition I
> need to test if any one of 31 columns is true. So right now I have my function looking something like:
> 
> 
> Insert into Table A (column 1, ... column n) (
> SELECT (column 1, ...column n) from Table B
> WHERE ( column  A OR column B OR ...repeated 31 times) = true
> [...]
> My question is there anyway that I can substitute the list of 31 of OR columns
> (always the same 31 column names) in my WHERE clause  with a "shortcut" so my code
> is shorter and cleaner. I need to create additional functions for other tables that
> use the same 31 ORs, so trying to find an easy way to reference this list of ORs
> across all my functions. Note, the additional WHERE clauses differ for each of the
> Unions, so I have them numbered 1,2,3 for the first SELECT, 4,5,6 for the second SELECT etc. 

It would be shorter to write

   WHERE TRUE IN (columnA, columnB, ...)

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


pgsql-novice by date:

Previous
From: "chandru.aroor@yahoo.com"
Date:
Subject: How to include/reference a common bit of code in a function
Next
From: rohan.parkes@dpc.vic.gov.au
Date:
Subject: pg_restore hangs on materialized view [SEC=UNCLASSIFIED]