Athena query to count rows for each table in Glue catalog

0

Hi,

Following from this article: Get record count for all tables in mysql database, is there an Athena on Presto version of the following MySQL query?

SELECT table_name
       , table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = schema_name;
1개 답변
1
수락된 답변

You can do this as a two step process.

  1. Dynamically building the SQL for getting the counts using the below query.
  2. Running the output of the SQL to generate the counts
with tname_vw(i) as (
    SELECT concat(
            'select ''',
            table_name,
            ''' as table_name,  count(*) from ',
            table_name
        )
    FROM information_schema.tables
    WHERE table_schema = 'schema_name'
)
select array_join(array_agg(i), ' union ') as result
from tname_vw

MK
답변함 일 년 전
  • Thanks MKB,

    this query returns one row with the following string:

    """ select table_1 as table_name, count() from table_1 union select table_2 as table_name, count() from table_2 ... """

  • AWS-learner, Once you run the Query within the sting, you should be seeing the counts for the respective tables in the schema. Does that address your issue?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠