What I'm trying to accomplish is to get aggregated data for all unique combinations of sendercompid, targetcompid, msgtype through all tables in inner SQL.
I expect to have from 20mil to 40mil unique rows in resulting output.
I cannot succeed in running next query on Postgresql 8.3.13:
SELECT
sendercompid, targetcompid, count(msgtype), msgtype
FROM
(SELECT table_name
FROM information_schema.tables
WHERE table_catalog = 'test'
AND table_schema = 'msg'
AND (table_name like 'fix_aee_20121214%') OR
(table_name like 'fix_aee2_20121214%')
)
WHERE
(sendercompid LIKE '%201%') OR
(targetcompid LIKE '%201%')
GROUP BY
sendercompid, targetcompid, msgtype ;
If this select is being split on 2 : outer and inner, then : inner will provide list of tables and outer will do select and grouping from each table .
If I run those two SQLs as one, I have an alias error from pgsql db
ERROR: subquery in FROM must have an alias
I tried use alias, but this error not disappear.
Any thoughts what I am missing there?
Thank you.