0

BIGINT value

Is there any way to return integer value from mysql?

Select CAST(1, int) is thowing error as this "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT) limit 0,1000' at line 1"

Select CAST(0 as SIGNED) OR Select CAST(0 as UNSIGNED) both are returing BIGINT value.

I have tried different method to cast value to int.

  • Does this answer your question? [Cast from VARCHAR to INT - MySQL](https://stackoverflow.com/questions/12126991/cast-from-varchar-to-int-mysql) – GSerg Feb 08 '23 at 13:10
  • The documentation says not.. why do you care? – P.Salmon Feb 08 '23 at 16:26

1 Answers1

0

I repost this answer

Create the function that will perform the conversion:

CREATE FUNCTION BigToInt (n BIGINT) RETURNS INTEGER RETURN n;

As you can see, the function is very short and simple: It takes a BIGINT and immediately returns it as an ordinary integer. However, one consequence of this is that some of the data will be truncated down to the largest possible value for Int.

Jonathan Delean
  • 1,011
  • 1
  • 8
  • 25