user2250152
user2250152

Reputation: 20670

Postgresql retrieve object properties

is there any way how to get table, view or database properties using sql query? When I open pgAdmin and select database, table or view there is tab Properties but I couldn't find any information in the documentation how to retrieve those properties using sql query. Thanks

Upvotes: 2

Views: 3287

Answers (2)

Renzo
Renzo

Reputation: 27424

All those informations can be collected by querying the system catalog, which is a set of relational tables and views containing all the metadata needed to operate the database management system.

For PostgreSQL see in the manual the System Catalogs chapter.

For instance, by querying the table pg_tables you can find the name and other information about the tables and views of the database, by querying pg_attribute you can find information about the columns, etc.

PgAdmin performs queries on those tables to show all the properties of the database objects.

The Catalog has always been an essential part of a relational database system, and in recent years it has also been standardized by the ANSI (Information schema), so that one can write queries working on different systems (until this standardization, each system has its own set of catalog tables, which in general contains more information).

Upvotes: 1

imtiyaz
imtiyaz

Reputation: 92

using (NpgsqlConnection con = new NpgsqlConnection("Server=Localhost;Port=5432;User Id=postgres;Password=postgres;Database=database4;"))
        {
            string myQuery = "SELECT id_, city_name, population FROM  tb_city_population WHERE  year_of = 2012";
            NpgsqlCommand cmd = new NpgsqlCommand();
            cmd.CommandText = myQuery;
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            con.Open();
            NpgsqlDataReader dr = cmd.ExecuteReader();

Upvotes: 0

Related Questions