Something like an SQL Paradox
I love philosophical problems translated into computer programs. And while reading SQL Cookbook, I thought I had come across another—a form of Russell’s Paradox.
Russell’s Paradox: a Review
You probably remember from logic class that Russell’s Paradox pointed out something very disturbing about naive set theory, namely that it is unclear whether or not the set of all sets not members of themselves are members of themselves. Or maybe you simply remember something about Barbers who shave only men who don’t shave themselves.
Oh, yeah!!! How does that go again?
Imagine a town, Russelltown, where there is a barber who- shaves all those men who don’t shave themselves, and
- doesn’t shave any man who does shave himself.
Does the Barber of Russelltown shave himself?
By 1, the Barber has to shave himself, but by 2, the Barber cannot shave himself.
So, it would seem that Russelltown has a barber who is not a man—an untenable solution. Where did we go wrong? Something must be wrong with our logic.
The general thought is that something is wrong with our axiomatic system.
SQL Groups as Sets
In SQL Cookbook, the author notes that a paradox arises for SQL groups.
What is a SQL group? A SQL group is a non-empty, distinct set. If you think about any SQL query that uses group by, this should be self evident. SQL groups can’t be empty otherwise it doesn’t really make much sense to call it a group—any nothing could be a group if empty groups are groups. SQL groups must be distinct otherwise we would say that our the database has not identified two sets of rows as similar.
The real problem arises for SQL groups when you consider the two facts about SQL groups in conjunction:- An SQL group can by definition not be empty. For instance, the aggregate function, COUNT returns a value >= 1. So, by definition, groups must have at least one member.
- SQL groups are syntactically promiscuous. To keep the SQL language flexible, NULL is a valid component of a SQL group by clause; however, NULLs are ignored by the group by function.
By 1, SQL groups cannot be empty, but by 2, SQL groups must be empty. Let’s take a closer look….
Consider the following table:
select * from femaleLogicians
Name
penelope maddy
ruth barcan marcus
susan haack
Consider that we insert several NULLs into the table like this…
insert into femaleLogicians values (NULL);
insert into femaleLogicians values (NULL);
insert into femaleLogicians values (NULL)
Given this table and the two facts above, what would you expect the following query to return?
select coalesce(name, 'NULL') as name,
count(name) from femaleLogicians
group by name;
The query would actually return something like this…
| name | count(name) |
|---|---|
| penelope maddy | 1 |
| ruth barcan marcus | 1 |
| susan haack | 1 |
| NULL | 0 |
This difficulty doesn’t arise by the definition of a SQL group alone; it arises by the definition of a SQL group and through the requirement that NULL values are valid SQL group components. Pretty cool, huh!! I’ll leave the work around solution as an exercise for the reader.
So, this SQL group “paradox” isn’t Russell’s paradox, but the similarity between a SQL group and a set makes one wonder whether it would be possible to create a group of all groups that do not contain themselves in SQL. I don’t believe syntatically something like that won’t work, but supposed your could rewrite the ISO SQL standard to accept such a syntax. Could you, with or without SQL, implement Russell’s paradox as a computer program? At very least, it appears that the problem can (like the problem of substitution into intensional contexts) be implemented using web pages in some way… maybe that will have to be fleshed out in another post.

