7

I don't want to know all data types, just all data types used in my database. Can this information be queried?

PostgreSQL 8.4 and 9.x versions

I currently need to know all data types for over 200 tables in public ( and other schemas )

asked Dec 5, 2012 at 22:36

1 Answer 1

13
select data_type, count(*) 
from information_schema.columns 
where table_schema = 'public' 
group by data_type ;

For other schemas just add: or table_schema = 'your_schema_name'.
If this will not satisfy you, you should look in pg_... or information_schema tables.

If you are looking for table information:

select data_type, count(*)
from information_schema.columns
where table_schema = 'public' and table_name = 'your_table_name'
group by data_type ;
answered Dec 5, 2012 at 23:01
5
  • 2
    very good answer. Commented Dec 6, 2012 at 2:55
  • What would be the equivalent for a specific table? Have tried replacing lines2/3 but I'm getting errors e.g.: could not Retrieve the result : ERROR: column "data_type" does not exist Commented Apr 2, 2014 at 10:05
  • @geotheory look on extended answer. Commented Apr 3, 2014 at 12:36
  • This is handy thanks. Ultimately I wonder about a query equivalent to the psql prompt \d table_name \g method, which lists fields and their datatypes, but since this method exists there's no urgency :) Commented Apr 3, 2014 at 22:10
  • what type does count(*) return: int or bigint? Commented Apr 10, 2014 at 14:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.