lpsmith / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
206 stars 71 forks source link

HStore implementation to parse NULL values and filter them out from the HStoreList #215

Open saurabhnanda opened 7 years ago

saurabhnanda commented 7 years ago

Fixes #215 Related to #214

This has a minor side-effect where hstores with NULL values will not really round-trip properly, i.e. if we read the following from the DB

"foo" => "bar", "fooNull" => NULL

we will get the following in Haskell

[("foo", "bar")]

and when stored back to the DB, it will get converted to:

"foo" => "bar"

This results in minor loss in fidelity. However, for all practical purposes, the absence of a key, and the key being assigned a NULL value is the same thing. How many programs out there would really be doing different things based on this condition?

saurabhnanda commented 7 years ago

@lpsmith what do you think of this approach? Pragmatically equivalent and doesn't introduce HStoreV2

lpsmith commented 7 years ago

I can't say I am overly enthusiastic about this filtering approach, but maybe I am softening on it somewhat. I would probably prefer a breaking interface change to the filtering approach here. While I find the HStoreV2 approach that you suggested acceptable, I am undecided regarding my preference between that and a breaking interface change. HStoreV2 is probably the "right thing", but a breaking change would avoid some ugliness in the longer run, though it might create some other ugliness.

saurabhnanda commented 7 years ago

From a usage standpoint, both HStoreList and HStoreMap return a Maybe whenever a key is looked up. In that sense they already have a way to handle NULLs. There isn't much to gain by changing HStoreList from [(Text, Text)] to [(Text, Maybe Text)]. Except one thing -- the ability to know if the key had a NULL value or was truly missing from the HSTORE.

I dont care about the pedantic difference between a missing key and a null-value key. What are your thoughts?

On 12-Jun-2017 2:36 AM, "Leon P Smith" notifications@github.com wrote:

I can't say I am overly enthusiastic about this approach, but maybe I am softening on it somewhat. I would probably prefer a breaking interface change to the filtering approach here. While I find the HStoreV2 approach that you suggested acceptable, I am undecided regarding my preference between that and a breaking interface change. HStoreV2 is probably the "right thing", but a breaking change would avoid some ugliness in the longer run, though it might create some other ugliness.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lpsmith/postgresql-simple/pull/215#issuecomment-307656848, or mute the thread https://github.com/notifications/unsubscribe-auth/AABu0RIPIW-gpGtpjtKz3_iLdDvcJiYwks5sDFbSgaJpZM4N2TzU .

saurabhnanda commented 6 years ago

@lpsmith did you get a change to decide on this?

saurabhnanda commented 6 years ago

@lpsmith any update on this?