Cast a column containing NaN as numerical

Hello, is it possible to cast a column that contains real values (ex: 1.01, 1.04, etc.) and NaN values, as a numerical column ?
My end goal is to be able to build custom columns when asking questions with metabase on this column.

Example:
To create column C = A + B, I need A and B to be of a numerical type.
(I know I could do it with sql CAST(A as FLOAT), but I want it to be doable from the ‘ask a question’ option.
Thanks all for your help :slight_smile:

Hi @MichaelU
I don’t quite understand what you’re trying to do, but Metabase doesn’t have a cast function in Custom Expressions, but real is like decimal, so you should be able to add those together without any problems.

Hi @flamber, thanks for the answer.
For more clarity:
I have one column that contains NaN’s, and for that reason, even when I specify that this column is of type numerical from the administrator menu, it is considered as text when I try to use it in custom columns.
I want to be able to perform standard numerical operations on this column, but I get an error that says I cannot add a column float with on of type text.

@MichaelU Please post “Diagnostic Info” from Admin > Troubleshooting, and which database you’re using.
And depending on the database, run this query on your table too:

DESCRIBE table_name;

Thanks,

here are the troubleshooting infos:

{

“browser-info”: {
“language”: “en-gb”,
“platform”: “MacIntel”,
“userAgent”: “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15”,
“vendor”: “Apple Computer, Inc.”
},
“system-info”: {
“file.encoding”: “UTF-8”,
“java.runtime.name”: “OpenJDK Runtime Environment”,
“java.runtime.version”: “11.0.8+10”,
“java.vendor”: “AdoptOpenJDK”,
“java.vendor.url”: “https://adoptopenjdk.net/”,
“java.version”: “11.0.8”,
“java.vm.name”: “OpenJDK 64-Bit Server VM”,
“java.vm.version”: “11.0.8+10”,
“os.name”: “Linux”,
“os.version”: “4.19.0-0.bpo.5-amd64”,
“user.language”: “en”,
“user.timezone”: “GMT”
},
“metabase-info”: {
“databases”: [
“postgres”
],
“hosting-env”: “unknown”,
“application-database”: “h2”,
“application-database-details”: {
“database”: {
“name”: “H2”,
“version”: “1.4.197 (2018-03-18)”
},
“jdbc-driver”: {
“name”: “H2 JDBC Driver”,
“version”: “1.4.197 (2018-03-18)”
}
},
“run-mode”: “prod”,
“version”: {
“date”: “2020-09-11”,
“tag”: “v0.36.5.1”,
“branch”: “release-0.36.x”,
“hash”: “a3459e8”
},
“settings”: {
“report-timezone”: “Europe/London”
}
}
}

@MichaelU You should migrate away from H2 if you’re using Metabase in production:
https://www.metabase.com/docs/latest/operations-guide/migrating-from-h2.html
Please read this - it almost sounds like the same problem:
Tables doesn't recognize data as numbers

Thant’s weird, I am actually configured on Postgres, as we can see in the admin/database panel:

I just updated to version v0.36.5.1 yesterday, maybe it’s related to that. I will go back to an earlier version and look again at troubleshooting infos.

@MichaelU I think you’re misunderstanding. The application database is where Metabase keeps all it’s information - by default it’s H2, which shouldn’t be used in production.

1 Like

Indeed, I see what you mean here thx !
Do you think this is the cause of my problem ?
For reminder :
Because there are null values in a column, the column is not treated as a numerical one but as text.

@MichaelU No, but H2 can easily become corrupted and doesn’t handle the same load as Postgres.

null shouldn’t be a problem since 0.36 (or perhaps it was 0.35), but I have a feeling that the field is incorrectly fingerprinted. Please see the other forum topic I linked to before.

Otherwise please provide a sample of your schema and data, so I can try to reproduce.