postgresql-ocaml
postgresql-ocaml copied to clipboard
managment of NULL
I would suggest to use Postgresql.null for null value. This way physical equality can distinguish the NULL value and the empty string. Accessing the result to know is a parameter is NULL is a bit annoying.
This is relatively fragile as OCaml could decide to share the representation of the null string. This is not done in 5.0.0.
But even in this case, Postgresl.null could be created from C or in other ways to avoid sharing.
A better solution could be a getoptvalue : int -> int -> string option
But this does not solve the problem of get_all and get_tuple. May be
get_optall and get_opttuple too ?
I finally decided that the when a column of type string may be null, then the empty string is equivalent to null. This mostly solved the issue. This is a good choice if using html form, when the empty string and undefined can not be distinguished.
I hesitate to close myself ... just leave a bit of time for someone to comment, before.
Chiming in... I was wondering why Postgresql.null
is actually set to the empty string rather than "NULL"
, which is the keyword to be passed as a parameter for exec
.
When reading data one can (and should) use the isnull
method so the string representation of the value does not matter, but when inserting new tuples using Postgresql.null
currently result in a parse error.
Scratching my head, maybe I'm doing something wrong?