Number of records in the PostgreSQL database table

Source: Internet
Author: User

 

PostgreSQL is not very familiar with it. I don't know if there is any good way to retrieve the number of records in all tables and tables in the data. Please tell us if you have any good methods. Thank you !!

 

There was a database with more than 200 tables in it, and a simple PHP program implementation was written in a stupid way.

 

Retrieve all tables

PostgreSQL # \ dt

 

Then I wrote a PHP program to get the number of table records. Of course, if your table is small, simply use select count (*) from table !!

<? PHP

 

$ Tables = "members
News
Newscatagory
Products
Productscatagory ";


$ Table_array = explode ("\ n", $ tables );
Foreach ($ table_array as $ v ){
$ V = trim ($ V );
Echo $ v .",";

$ T = table_records ($ V );
Echo $ T. "<br> ";
}

 

Function table_records ($ v) {// obtain the number of records in the table
Global $ dB;
If ($ v ){
$ RT = $ db-> get_one ("select count (*) as count from $ v ");
Return $ RT ['Count'];
} Else {
Return 0;
}
}

?>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.