Created
August 7, 2024 16:02
Revisions
-
Pxtl created this gist
Aug 7, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ -- The following code works in MS SQL 2019 -- But fails in Postgres 14.12 (PG 14 was released in 2021) DROP TABLE IF EXISTS EMPLOYEE; -- create CREATE TABLE EMPLOYEE ( empId INTEGER PRIMARY KEY, name VARCHAR(50) NOT NULL, dept VARCHAR(50) NOT NULL ); -- insert INSERT INTO EMPLOYEE VALUES (0001, 'Clark', 'Sales'); INSERT INTO EMPLOYEE VALUES (0002, 'Dave', 'Accounting'); INSERT INTO EMPLOYEE VALUES (0003, 'Ava', 'Sales'); -- fetch SELECT CASE WHEN EXISTS ( SELECT * FROM EMPLOYEE GROUP BY dept HAVING Count(*) > 1 ) THEN 'there exists a dept with multiple employees' ELSE 'there are no depts with multiple employees' END AS Result;