![]() ![]() If the expression cannot be converted to the target type, PostgreSQL will raise an error. The following statement converts a string constant to an integer: SELECT CAST ( '100' AS INTEGER) Code language: SQL (Structured Query Language) ( sql ) Let’s take some examples of using the CAST operator to convert a value of one type to another. Notice that the cast syntax with the cast operator (::) is PostgreSQL-specific and does not conform to the SQL standard PostgreSQL CAST examples '0':: DATE Code language: SQL (Structured Query Language) ( sql ) ![]() See the following example: SELECT '100':: INTEGER, Then, specify the target data type to which you want to convert the result of the expression.īesides the type CAST syntax, you can use the following syntax to convert a value of one type into another: expression::type Code language: SQL (Structured Query Language) ( sql ).First, specify an expression that can be a constant, a table column, an expression that evaluates to a value.The following illustrates the syntax of type CAST: CAST ( expression AS target_type ) Code language: SQL (Structured Query Language) ( sql ) PostgreSQL provides you with the CAST operator that allows you to do this. There are many cases that you want to convert a value of one data type into another. Summary: in this tutorial, we will show you how to use PostgreSQL CAST operator to convert a value of one type to another. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |