Some SQL needed for commit 56cd0fc29aa57c74b55cb7c4854a1111d9c487ef