I would like to get field's name, datatype of each field, length of each field and precision of each field of a PostgreSQL table. Please let me SQL query to get this information.
The simplest way in SQL is to query the
information_schema.columns view with a WHERE clause on
table_name matching yours. All the properties you want (and more) are in the output columns of this single view.
This view is part of the Information Schema whose purpose is to provide standard ways to do database introspection.
I suggest you use pg_dump to get tables' and views' definition, it's more convenient. The following command gets the definition of the database
pg_dump -h 127.0.0.1 -E UTF8 -s -v francs > francs.ddl
-s means only dump matching schema, not data.
All the information used to define each table,column,function etc is stored in the System Catalogs. The contents of these system tables are explained in the manual
Using psql you get easy access to pre-formatted display of this information. Type \? to list available options (under Informational).
If you wish to extract this data to use in your own app then you will probably find looking through the source code of psql an easy way to find examples of selecting the data.