


Once you are connected to the targeted database, type the “\dt” command to see the list of available tables in that database: \dt You have to follow the below-listed procedure to change the column’s data type:įirstly, open SQL SHELL and type the “\c” command followed by the database name to make a connection with the selected database: \c example
#POSTGRES ALTER COLUMN DATA TYPE HOW TO#
new_data_type represents the altered/modified data type of the selected column.Įxample: How to Change/Modify the Column’s Type From int to text? col_name represents the column to be altered. tab_name represents a table whose column will be altered. Let’s analyze the above-given syntax step-by-step: The below-given syntax will assist you in changing the data type of any particular column: ALTER TABLE tab_nameĪLTER COLUMN col_name TYPE new_data_type

How to Change/Update the Column’s Data Type in Postgres? So, without any further delay, let’s start. This blog will present a step-by-step guide on changing the column’s data type. In PostgreSQL, we can change the data type of one or more than one column using the “ALTER TABLE” and “ALTER COLUMN” commands. For example, integer to character, text to varchar, and so on. In PostgreSQL, the “ALTER TABLE” and “ALTER COLUMN” commands, along with the TYPE Keyword, are used to change/modify the data type of a column.
