HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

query to identify all data types used in postgresql database tables

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqltablesallusedidentifyquerydatabasetypesdata

Problem

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 )

Solution

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 ;

Code Snippets

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

Context

StackExchange Database Administrators Q#29901, answer score: 11

Revisions (0)

No revisions yet.