Thread: searching a value in a variable/field in all tables in a schema

searching a value in a variable/field in all tables in a schema

From
Ruiqiang Chen
Date:

Does anyone have experience of searching a value in a variable/field in all tables in a schema? 


If you can provide some code not creating stored procedure that would be great. 

Thanks,
Ray

Re: searching a value in a variable/field in all tables in a schema

From
"David G. Johnston"
Date:
On Thu, Aug 30, 2018 at 1:44 PM, Ruiqiang Chen <chenrq2005@gmail.com> wrote:

Does anyone have experience of searching a value in a variable/field in all tables in a schema? 

 
SELECT 'Tbl1'::text AS loc, fld
FROM schema.tbl1
WHERE fld = 'value'
[UNION ALL
SELECT 'Tbl2'::text AS loc, fld
FROM schema.tbl2
WHERE fld = 'value'
...]

David J.

Re: searching a value in a variable/field in all tables in a schema

From
Ruiqiang Chen
Date:
Thanks! 

On Thu, Aug 30, 2018 at 4:51 PM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thu, Aug 30, 2018 at 1:44 PM, Ruiqiang Chen <chenrq2005@gmail.com> wrote:

Does anyone have experience of searching a value in a variable/field in all tables in a schema? 

 
SELECT 'Tbl1'::text AS loc, fld
FROM schema.tbl1
WHERE fld = 'value'
[UNION ALL
SELECT 'Tbl2'::text AS loc, fld
FROM schema.tbl2
WHERE fld = 'value'
...]

David J.