I'd like to audit specific user activity across our application's database. Most of the important tables have these metadata fields:
- id
- date_last_edited
- last_edited_by
I've got a prototype working:
with "params" as (
select
'DeethJ' as user,
'2022-09-01' as from_date,
'2022-09-30' as to_date
)
select 'address' as "table", id, date_last_edited, last_edited_by
from address
join params
on last_edited_by = params.user
and date_last_edited between params.from_date and params.to_date
union
select 'person' as "table", id, date_last_edited, last_edited_by
from person
join params
on last_edited_by = params.user
and date_last_edited between params.from_date and params.to_date
union
select 'person_person_relationship' as "table", id, date_last_edited, last_edited_by
from person_person_relationship
join params
on last_edited_by = params.user
and date_last_edited between params.from_date and params.to_date
Is there a way I can provide a list of table names and do the same query on each one - some kind of union_agg function?
Constraints: the database is PostgreSQL 9.6 (yes, I know, they said they will update it), my access is the "Freehand SQL data source" within SAP BusinessObjects so I can only provide a single statement. I cannot create a function or procedure.
Prospects look dim so I might instead generate the query in Excel...
UNIONfor you.