GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
See, for example, #4; we should add support for network addresses and universally unique identifiers among others.
Also, Haskell's UTCTime doesn't support infinity or -infinity, whereas PostgreSQL's timestamp type does.
I'm interested in adding UUID to the list of supported types, pulling in the UUID type from the uuid package on hackage. I'm going to try to fork and add it, but I'm still a bit of a newb with Haskell, so not sure how well that's going to go. Before I spend a bunch of time trying to work out the details of that do you have any objection to pulling in a dependency on uuid?
The work to add support for UUID is mostly done, I just need to add some tests around the new code and then I'll be ready to issue a pull request.
Sorry for not responding a little sooner. This is actually a surprisingly common question.
The answer is that you don't need to modify postgresql-simple at all, all you have to do is add a FromField instance for the Haskell type you want to represent UUIDs. I've been meaning to add this exact case as sample code in FromField, actually. Also, you might be interested in looking at the improved FromField documentation in the 0.3 branch.
Here's something that should be pretty close to being correct:
instance FromField UUID where
fromField f mdata =
if typeOid f /= builtin2oid UUID
then returnError Incompatible ""
else case B.unpack `fmap` mdata of
Nothing -> returnError UnexpectedNull ""
Just data ->
case [ x | (x,t) <- reads data, ("","") <- lex t ] of
[x] -> Ok x
_ -> returnError ConversionError data
Since postgresql's UUID type has a stable oid, we can look at that. For types provided by extensions, such as hstore, you should use the typename operator instead, e.g. if typename f /= "hstore" then ....
if typename f /= "hstore" then ...
Also, I will say that I have considered adding out-of-box support for UUIDs, but after consulting some of the postgresql-simple users that use UUIDs we decided to keep postgresql-simple more minimal, with fewer dependencies on this count for the time being.
Wouldn't you also need to create a ToField instance for the UUID type? The work I've done so far was to create a FromField and ToField instance and it seems to work, although I suppose I can see not wanting to pull in the extra dependency just to support UUID. I suppose I could always make the instances a standalone module, something like postgresql-simple-uuid.
Depends on your needs, but for whatever reason ToField instances for UUID aren't asked about as often. We should offer both for out-of-box UUID support, though.
Well, there's more work to be done, on this issue, but there's always more work to be done on this issue. I haven't added out-of-box support for network addresses (yet?), and decided against out-of-box support for UUIDs for the time being although I may change my mind, and have included a UUID FromField instance as an explicit example in the documentation. However recent versions do support arrays and hstores, and I have rewritten the time parsers.
So given that this is a fairly generic and on-going issue, I'm going to close it. If anybody wants to request support for another specific type, feel free to open another issue.