![]() ![]() ![]() Maybe the database layer should allow abstraction to promote / convert types. This problem denotes that some types were not chosen correctly. I could not yet test this cast under MySQL. Typecasting refers to the process of manually changing the data type of an expression. It will help in casting the specified expressions to a specified data type. The reason is that timezone is a CHAR value and not an integer.Ī possible solution is to cast the data explicitely: UPDATE users SET timezone_id = 320 WHERE timezone = CAST(7200 AS VARCHAR) AND timezone_id = 0 When working with a number different of data types the MySQL CAST () function comes in handy. This query works under MySQL and fails under PostgreSQL: UPDATE users SET timezone_id = 320 WHERE timezone = 7200 AND timezone_id = 0 In the case of PostgreSQL, this prevents wrong casts when different locales or timestamps are used. From any alphanumerical type to any alphanumerical type.From any numerical type to any numerical type.This is not the case of PostgreSQL, which only automatically casts data: MySQL allows to cast data from any type to any type in SQL queries. This is only one valid reason for not casting, there may be several other reasons. For example, 1.2 (integer) can be '1,2' in French and '1.2' in English. SELECT a.revenue AS arevenue, b.revenue AS brevenue, c.revenue AS crevenue FROM ( SELECT CAST(SUM(revenue) AS CHAR) revenue FROM PA WHERE siteid 2 AND datadate BETWEEN '' AND '' ) a, ( SELECT CAST(SUM(revenue) AS CHAR) revenue FROM PB WHERE siteid 2 AND. The reason is that such a cast may vary depending on locales and the representation of numbers. Since each query will return a 1-row, 1-column result, you can just do a Cartesian join, i.e. SQL-99 forbids to cast data between integer and alphanumerical values. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |