The expression after the USING keyword can be as simple as column_name::new_data_type such as price::numeric or as complex as a custom function. In case the cast fails, PostgreSQL will issue an error and recommends you provide the USING clause with an expression for the data conversion. If you omit the USING clause, PostgreSQL will cast the values to the new ones implicitly. The USING clause specifies an expression that allows you to convert the old values to the new ones. PostgreSQL allows you to convert the values of a column to the new ones while changing its data type by adding a USING clause as follows: ALTER TABLE table_nameĪLTER COLUMN column_name TYPE new_data_type USING expression Ĭode language: SQL (Structured Query Language) ( sql ) In this syntax, you add a comma ( ,) after each ALTER COLUMN clause. ![]() Code language: SQL (Structured Query Language) ( sql ) To change the data types of multiple columns in a single statement, you use multiple ALTER COLUMN clauses like this: ALTER TABLE table_nameĪLTER COLUMN column_name1 TYPE new_data_type,ĪLTER COLUMN column_name2 TYPE new_data_type, The SET DATA TYPE and TYPE are equivalent. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |