You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Selecting a numeric field and formatting as text fails to return the currency symbol with this format string.
Example postgres query
Select to_char(100.99,'FML999,999.00') in PgAdmin and psql outputs £100.00 ( in the UK ) , but the symbol £ coming through as a blank space ( which to me indicates an encoding problem ) in DOTNET DataTable - however if using Postgres ODBC driver the symbol comes through fine.
This is the current expected behavior of Npgsql. We set the "lc_monetary" to "C" on startup, meaning that for monetary purposes we are in a culture-invariant locale - so no currency symbol is produced. This is (currently) necessary for Npgsql to parse textual currency values without having to deal with locale variations.
Note that setting this parameter is causing trouble elsewhere as well (#163).
Let us research things a little, we may be able to handle currency types without setting lc_monetary to C. If this is possible it will fix both issues.
I'm not familiar with the type conversion code, but this seems to be an attempt to deal with all localized currency types. If this works, then it shouldn't be necessary to set LC_MONETARY to C, right?
The problem I faced in the past was that on some locales, negative money
values were sent as $(value) and I received complains where the dolar sign
was in the middle of the value (I don't recall the locale where this
appears.) That's why I decided to go with lc_monetary = C . This way we
would need to parse only one type of money representation.
Em 06/09/2014 14:21, "Shay Rojansky" [email protected] escreveu:
I'm not familiar with the type conversion code, but this seems to be an
attempt to deal with all localized currency types. If this works, then it
shouldn't be necessary to set LC_MONETARY to C, right?
Do you have any history on this?
—
Reply to this email directly or view it on GitHub #266 (comment).
Hi all, I'm the one that posted the issue - do I take it that there's not going to be a fix on this ? It's not a huge issue for me as I've found a workaround for my purposes but surely it can't be that difficult to do ? If you can return the currency symbol in a normal string why can't it be done just because it's attached to a converted money value ? I'm obviously missing something here :-(
@pkfox, we definitely intend to work on this for the 3.0 version (as this is a breaking change). I have personally been concentrating on other issues, but sooner or later we'll get around to this.
The point is that returning the currency symbol means giving up lc_monetary=C (invariant culture), which means we need to parse all locale versions of currency values. It's not necessary impossible but needs to cover all the cases. This is why we moved to invariant in the first place.
So I think it will be done, but it may take some time.
Ok thanks for your reply but as to_char() returns a string I can’t see why prefixing the string with a “£” or “$” or whatever poses a problem and I don’t know what lc_monetary means :) thanks again for your time
@pkfox, we don't want to prefix the currency symbol ourselves - this is Postgresql's job. Postgresql normally returns a fully localized string, with the currency symbol, the correct separators, etc. (in text mode).
This mode is great for purely textual operations, but when users want to receive money as double it becomes npgsql's job to parse the localized currency string. This is why at some point we decided to get rid of this headache by telling the Postgresql backend to sent invariant strings - no more localization.
This mode is great for purely non-textual operations (doubles), but screws up the situation for textual users who want the currency symbol, separators, etc.
Sets the locale to use for formatting monetary amounts, for example with the to_char family of functions. Acceptable values are system-dependent; see Section 22.1 for more information. If this variable is set to the empty string (which is the default) then the value is inherited from the execution environment of the server in a system-dependent way.
Thanks for the offer, we can definitely use the help. Right now things are two volatile with the v3.0 rewrite, but as things stabilize then sure. Any specific area you're interested in or a feature you'd like to add?
Hi Shay, I’m interested in all of it but If anything needs some work I think it’s support for Entity Framework, I’ve tried to use it but got to the point where I realised it doesn’t map to functions yet and gave up
I admit EF it's definitely not my area in Npgsql - @Emill is the guy who knows most about that. One good point is that it's a separate project from the Npgsql core and is pretty loosely-coupled from it, so you wouldn't be affected by the massive refactoring going on in the core (at least in theory).
I guess any pull requests which improve EF would be great, anything to add here @Emill?
That would be great. Yes, EF is quite separate from the rest of Npgsql, so
you can start working on it if you want to. We however have a pull request
for functions here: #129. Maybe you
could review that first?
I admit EF it's definitely not my area in Npgsql - @Emill https://github.com/Emill is the guy who knows most about that. One good
point is that it's a separate project from the Npgsql core and is pretty
loosely-coupled from it, so you wouldn't be affected by the massive
refactoring going on in the core (at least in theory).
The monetary setting lc_monetary also affects binary read/write, since it tells how many digits should be the fraction part. While I agree this is kind of broken by design that the actual value of the number should depend on a runtime parameter, we could read the lc_monetary setting. But since this is just a string of the name of the language/country (that depends on operating system), it's quite hard to figure out how many digits to use.
Since money is classified as an obsolete data type that still exists for backwards-compatibility, and most countries (I think?) use 2 decimals, we should probably just assume it is 2 decimals. That is what we do currently anyway by setting locale to C.
Activity
roji commentedon Sep 6, 2014
Sorry for not replying to this earlier.
This is the current expected behavior of Npgsql. We set the "lc_monetary" to "C" on startup, meaning that for monetary purposes we are in a culture-invariant locale - so no currency symbol is produced. This is (currently) necessary for Npgsql to parse textual currency values without having to deal with locale variations.
Note that setting this parameter is causing trouble elsewhere as well (#163).
Let us research things a little, we may be able to handle currency types without setting lc_monetary to C. If this is possible it will fix both issues.
roji commentedon Sep 6, 2014
@franciscojunior, looking at our money conversion code I see this conversion code: https://github.com/npgsql/Npgsql/blob/master/Npgsql/NpgsqlTypes/NpgsqlTypeConvBackendToNative.cs#L298
I'm not familiar with the type conversion code, but this seems to be an attempt to deal with all localized currency types. If this works, then it shouldn't be necessary to set LC_MONETARY to C, right?
Do you have any history on this?
franciscojunior commentedon Sep 6, 2014
Hi, Shay!
The problem I faced in the past was that on some locales, negative money
values were sent as $(value) and I received complains where the dolar sign
was in the middle of the value (I don't recall the locale where this
appears.) That's why I decided to go with lc_monetary = C . This way we
would need to parse only one type of money representation.
Em 06/09/2014 14:21, "Shay Rojansky" [email protected] escreveu:
pkfox commentedon Sep 18, 2014
Hi all, I'm the one that posted the issue - do I take it that there's not going to be a fix on this ? It's not a huge issue for me as I've found a workaround for my purposes but surely it can't be that difficult to do ? If you can return the currency symbol in a normal string why can't it be done just because it's attached to a converted money value ? I'm obviously missing something here :-(
roji commentedon Sep 18, 2014
@pkfox, we definitely intend to work on this for the 3.0 version (as this is a breaking change). I have personally been concentrating on other issues, but sooner or later we'll get around to this.
The point is that returning the currency symbol means giving up lc_monetary=C (invariant culture), which means we need to parse all locale versions of currency values. It's not necessary impossible but needs to cover all the cases. This is why we moved to invariant in the first place.
So I think it will be done, but it may take some time.
pkfox commentedon Sep 18, 2014
Ok thanks for your reply but as to_char() returns a string I can’t see why prefixing the string with a “£” or “$” or whatever poses a problem and I don’t know what lc_monetary means :) thanks again for your time
roji commentedon Sep 18, 2014
@pkfox, we don't want to prefix the currency symbol ourselves - this is Postgresql's job. Postgresql normally returns a fully localized string, with the currency symbol, the correct separators, etc. (in text mode).
This mode is great for purely textual operations, but when users want to receive money as double it becomes npgsql's job to parse the localized currency string. This is why at some point we decided to get rid of this headache by telling the Postgresql backend to sent invariant strings - no more localization.
This mode is great for purely non-textual operations (doubles), but screws up the situation for textual users who want the currency symbol, separators, etc.
Hope this makes the problem clear.
pkfox commentedon Sep 18, 2014
Ah I see ! Thanks for claryfing things , by the way what is lc_monetary ?
roji commentedon Sep 18, 2014
lc_monetary is just a Postgresql variable that tells the backend how to format currency types. Setting it to C makes formatting be culture-invariant.
From http://www.postgresql.org/docs/9.3/static/runtime-config-client.html
pkfox commentedon Sep 18, 2014
OK thanks
3 remaining items
roji commentedon Jan 13, 2015
Thanks for the offer, we can definitely use the help. Right now things are two volatile with the v3.0 rewrite, but as things stabilize then sure. Any specific area you're interested in or a feature you'd like to add?
pkfox commentedon Jan 13, 2015
Hi Shay, I’m interested in all of it but If anything needs some work I think it’s support for Entity Framework, I’ve tried to use it but got to the point where I realised it doesn’t map to functions yet and gave up
roji commentedon Jan 13, 2015
I admit EF it's definitely not my area in Npgsql - @Emill is the guy who knows most about that. One good point is that it's a separate project from the Npgsql core and is pretty loosely-coupled from it, so you wouldn't be affected by the massive refactoring going on in the core (at least in theory).
I guess any pull requests which improve EF would be great, anything to add here @Emill?
Emill commentedon Jan 13, 2015
That would be great. Yes, EF is quite separate from the rest of Npgsql, so
you can start working on it if you want to. We however have a pull request
for functions here: #129. Maybe you
could review that first?
2015-01-13 13:53 GMT+01:00 Shay Rojansky [email protected]:
Emill commentedon Jan 13, 2015
The monetary setting lc_monetary also affects binary read/write, since it tells how many digits should be the fraction part. While I agree this is kind of broken by design that the actual value of the number should depend on a runtime parameter, we could read the lc_monetary setting. But since this is just a string of the name of the language/country (that depends on operating system), it's quite hard to figure out how many digits to use.
Since money is classified as an obsolete data type that still exists for backwards-compatibility, and most countries (I think?) use 2 decimals, we should probably just assume it is 2 decimals. That is what we do currently anyway by setting locale to C.
roji commentedon Jan 13, 2015
Ah I didn't know binary encoding was sensitive to lc_monetary, that really sucks...
I guess you're right though, 2 decimals sounds like the way to go.