Skip to content
Advertisement

Tag: casting

Converting decimal to Date

I have a column with dates formatted as decimals, for example: 20,210,830. I want to convert this number to date format as 08/30/2021 I have tried to use convert and the database shoots me an error that convert is not a valid function. Cast seems to work but, only returns a null value every time. This statement will validate: This

Lower bound for Postgres integer type out of range?

Per Postgres documentation, an integer type is defined between -2147483648 and +2147483647. I thought that these boundaries were inclusive, but if I try: an Integer out of range error is raised. The upper bound seems to be casted properly: And if I increase the lower bound by one it works fine as well: The same result is applied to smallint.

Order of CAST() and COALESCE() matters in MariaDB

I have a strange problem: There is a price in a JSON column in a table and the following statements give different results while they should give the same thing: Just to check I also added a JSON_EXTRACT(item.price_details, “$.shipping.price”) AS shipprice Result: MariaDB version: mariadb Ver 15.1 Distrib 10.3.31-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2 DB Fiddle (I couldn’t use

Convert character to number, like +00005 to 5

We have the fixed format data and it has the number with plus/minus sign, like +00005 or -00005. We’d like to convert it to number but Redshift seems not to allow implicit conversion. So, I temporarily use to_number(replace(<numbercolumn>, ‘+’, ”),’99999′) But I guess there should be more better solutions. Anyone know more smart way, your advice would be highly appreciated.

What is the type casting hierarchy in mysql?

Taking the following example: If I only include the first select statement in the cte, the type will be int. If I include the first and second, the type will be DECIMAL, and if I include all three, the type will be cast to VARCHAR (regardless of position of the three statements). How does mysql determine which type to cast

datetime.datetime conversion to datetime

I have defined a column in SQL Server as ldate with datetime data type and accepting null values. I’m trying to send data from my local machine using python and pyodbc. I have date like 20-01-2015 in string format. When I try to send data it throws an error: pyodbc.DataError: (‘22007’, ‘[22007] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed

Advertisement