Sql Insert Case When Postgresql Tutorial Joins