Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return size of table as MB not KB

Using Postgres to return the size of a table

SELECT pg_size_pretty(pg_table_size('zlimitreacjed_1')); 

returns '1632 kb'....is there anyway to return this value as MB as opposed to kb's?

like image 539
John Avatar asked Apr 14 '16 09:04

John


1 Answers

Judging by the documentation here, pg_size_pretty automatically adjusts as appropriate. If you want to use megs regardless, you could just use

SELECT pg_table_size('zlimitreacjed_1') / 1024 /1024 || 'MB'; 

pg_table_size returns bytes, so just divide it by 1024 a bunch of times, depending on what you want (once for kb, twice for mb, thrice for gb and so on).

like image 144
Mihai P. Avatar answered Oct 31 '22 00:10

Mihai P.