Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 493

Get count of rows from multiple tables Redshift SQL?

$
0
0

I have a redshift database that is being updated with new tables so I can't just manually list the tables I want. I want to get a count of the rows of all the tables from my query. So far I have:

select 'SELECT ''' || table_name || ''' as table_name, count(*) As con ' ||'FROM ' || table_name ||         CASE WHEN lead(table_name) OVER (order by table_name ) IS NOT NULL         THEN ' UNION ALL ' ENDFROM INFORMATION_SCHEMA.TABLESWHERE TABLE_NAME LIKE '%results%'

but when I do this I get the error:

Specified types or functions (one per INFO message) not supported on Redshift tables.

I've searched a lot but I can't seem to find a solution for my problem. Any help would be greatly appreciated. Thanks!

EDIT:I've changed my approach to this and decided to use a for loop in R to get the row counts of each but I'm running into the issue that 'row_counts' is only saving one number, not the count of each row like I want. Here is the code:

schema <- "x"table_prefix <- "results"geos <- ad_districts %>% filter(geo != "geo")row_count <- list()i = 1for (geo in geos){  table_name <- paste0(schema, ".", table_prefix, geo)  row_count[[i]] <- dbGetQuery(con,                              paste("SELECT COUNT(*) FROM", table_name))  i = i + 1 }

Viewing all articles
Browse latest Browse all 493

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>