Conversation
during string interpolation if dotnet culture is set to French it used comma as the decimal separator instead of period, which cased SQL error "unexpected ,"
|
Interesting, also considering that one could run Postgres with a French locale, so there's no straightforward fix. This issue probably affects other parts of the code What about changing the .NET locale instead of changing the code? is it possible? |
|
In my current project it is possible to change locale of .NET, but I can imagine that it won't be possible for many other teams/projects. Changing the locale in PostgreSQL to French will not change the way it handles decimal delimiters, it follows the SQL standard that always uses "." periods. It only affects parsing and formatting, there are some functions like here but internal representation of numbers always uses periods. So, we may use but that would work only if the database and the .NET app both use the same locale, and in my case .NET is 'fr-FR' and database is 'en-US' and it gives error because in my case if let's say maxDistance is 0.82 the SQL would be That's why I think the solution here is to explicitly convert number to string |
|
what about using a parameter instead? - filterSql += $" AND {this._colEmbedding} <=> @embedding < {maxDistance.ToString(CultureInfo.InvariantCulture)}";
+ filterSql += $" AND {this._colEmbedding} <=> @embedding < @maxDistance"; cmd.Parameters.AddWithValue("@embedding", target);
+ cmd.Parameters.AddWithValue("@maxDistance", maxDistance); |
5ac1d50 to
68e0a9f
Compare
Yes this way it's much cleaner (and it works as expected) ✅ |
|
For the record, this fixes a regression introduced in #684 |
Motivation and Context (Why the change? What's the scenario?)
During string interpolation if dotnet culture is set to French it used comma as the decimal separator instead of period, which cased SQL error "unexpected ,"
High level description (Approach, Design)
Forcing culture-insensitive cast using
maxDistance.ToString(CultureInfo.InvariantCulture)