I'm working with MySQL's INFORMATION_SCHEMA schema to automate some processing on generic columns in tables.
One task is to identify numeric and non-numeric column types to apply specific operations in the two cases.
Of course I can define operations for each single data type in MySQL and solve my issue that way, but I'm wondering whether using a solution like:
SELECT
NUMERIC_PRECISION
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA='aschema' AND
TABLE_NAME='atable' AND
COLUMN_NAME='acolumn'
when transversing tables and columns could be good enough to have a rough separation between the two kind of columns I'm interested in.
My goal would be having a TRUE/FALSE identifying a column to contain numeric data type or not.
Any other idea is welcome.
Drawbacks point-out is welcome too.
I vote for NUMERIC_PRECISION IS NOT NULL
. It includes "bit". To exclude "bit", use NUMERIC_SCALE IS NOT NULL
. If you want to argue that "enum" or "year" are numeric, then go with an IN-clause like Dudi's.