Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get column size and type through my database in PostgreSQL

Tags:

I've changed column length manually in my previous database.

But after creating new database via HQL it's creating varchar(255) and I need to make it longer.

I need to find which table's column should I change?

I can find it manually but now I have about 200 tables and I need a query to do this.

How can I get the column type and its length in Postgres using a SQL query?

like image 501
Jama A. Avatar asked Dec 17 '10 15:12

Jama A.


People also ask

How do I fetch a column in a database?

To get the column name of a table we use sp_help with the name of the object or table name. sp_columns returns all the column names of the object. The following query will return the table's column names: sp_columns @table_name = 'News'


1 Answers

The INFORMATION_SCHEMA tables will help you here:

select * from INFORMATION_SCHEMA.COLUMNS 

You can examine the table_name, column_name, data_type and character_maximum_length columns in the result set.

like image 168
D'Arcy Rittich Avatar answered Oct 22 '22 04:10

D'Arcy Rittich