![]() ![]() ![]() The output authenticates that the data type of the “team_rating” column has been updated to the character type. Let’s run the “\d” command followed by table name to see the changes made to the selected table: \d team_info Select a table and run the following command to see the structure of the selected table: \d team_info Įxecute the below-given command to change the data type of the “team_rating” column from “integer” to “character”: ALTER TABLE team_infoĪLTER COLUMN team_rating TYPE VARCHAR(30) 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 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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |