Unable to create a check constraint for NaN values

I am working to prevent any chance of NaN from being inserted into my DB, so I created a check constraint that looks like the following: (table) => [ check("fancy_check_name", sql${table.amount} <> NaN), ], When I run drizzle-kit's push method, I get the following error, "error: column "nan" does not exist" Any combination of quotes or anything around NaN makes no difference.
Any Ideas?
3 Replies
Angelelz
Angelelz4w ago
Couple ideas on how to check if a value is NaN there https://stackoverflow.com/questions/25858859/how-to-check-if-number-is-nan
Stack Overflow
How to check if number is NaN
I need to test if a numeric/float value in PostgreSQL is not a number (NaN). Note that "PostgreSQL treats NaN values as equal". As I'm not seeing any isnan function in PostgreSQL 9.3, her...
MUG Knight
MUG KnightOP4w ago
I am able to NOT get an error when running with a check constraint that looks like this: sqlnullif(${table.amount}, 'NaN') is not null But... When I query the DB to see what contraints/indexes exist on my table with this defined in the drizzle schema, there is no check onstraint... I stand corrected. The query I wrote to get the indexes/constraints was incorrect. They are there now.
Angelelz
Angelelz4w ago
I think that you need to cast ‘NaN’ as numeric, check the SO
Want results from more Discord servers?
Add your server