On Sat, Sep 14, 2019 at 4:45 AM Peter Bex <xxxxxx@more-magic.net> wrote:

This sounds extremely painful to work with, especially when you know that
NULLs are never there, even if the column itself may be nullable (due to
a WHERE condition, for example).

There's also a problem with this definition, because you can't know what
column a value is coming from.  Also, it might not even map to a column
at all:  (SELECT 1, 'foo' UNION SELECT NULL, NULL); will have a result
set which is typed as int, text.  There's no information on whether the
types may be nullable.

Type inference can solve all these problems:  your UNION's columns are typed Maybe(Integer), Maybe(String).  But I agree that that is more work than needs to be done for this SRFI.

I still like the idea of identifying NULL with Nothing, even if it's too hard to decide when to wrap data in Just and when not to.
 
> So let's defer consideration of [arrays].

Sure, most databases don't have them, so it's more of a driver-specific
issue I think.

Oracle and PostgreSQL do; SQLite, MySQL, and SQL Server don't.
 
You can't distinguish from spaces added by the padding of the CHAR(n)
type and spaces that were present in the original string. 

Sure, which is as much as to say: if you care about whether trailing blanks are present or not, don't use CHAR types.  But again, it's probably too much work to notice that a column is of type CHAR rather than VARCHAR and trim it.  Not all databases care about the distinction, however: Oracle does not and neither does SQLite.

Indeed, SQLite doesn't even parse the types you specify in CREATE TABLE statements: it just uses the following rules:

1) if the type contains the string "INT", the column has integer affinity (coerces strings and floats to integers if possible, otherwise leaves them alone..

2) If the type contains the strings "CHAR", "TEXT", or CLOB", the column has string affinity (coerces numbers to strings).

3) If the type contains the strings "REAL", "FLOA", or "DOUB", the column has float affinity (coerces integers to floats, and coerces strings to floats if possible).

4) If the type contains the string "BLOB" or is not specified at all, the column has "any" affinity (no coercion).

5) Otherwise the column has numeric affinity (strings are coerced to integers if possible; if not, to floats if possible; if not that either, they are left alone).

So if you write "CREATE TABLE FOO(BAR INTERNATIONALIZED_STRING)" it works and is exactly the same as CREATE TABLE FOO(BAR INTEGER(5)).


John Cowan          http://vrici.lojban.org/~cowan        xxxxxx@ccil.org
Consider the matter of Analytic Philosophy.  Dennett and Bennett are well-known.
Dennett rarely or never cites Bennett, so Bennett rarely or never cites Dennett.
There is also one Dummett.  By their works shall ye know them.  However, just as
no trinities have fourth persons (Zeppo Marx notwithstanding), Bummett is hardly
known by his works.  Indeed, Bummett does not exist.  It is part of the function
of this and other e-mail messages, therefore, to do what they can to create him.