简体   繁体   中英

How to select if `col1 = 0 OR col2 = 0 OR col3 != null` statement in postgresql?

How to select if col1 = 0 OR col2 = 0 OR col3 != null statement in postgresql ?

var query = 'SELECT * FROM "Media" WHERE "MediaId" = $1 AND ("AType" = 0 OR "BType" = 0 OR "C" != null)';


CREATE TABLE IF NOT EXISTS "Media"(
"MediaId" SERIAL NOT NULL,
"AType" integer,
"BType" integer,
"C" varchar,
PRIMARY KEY ("MediaId")
);



MediaId | AType | BType | C
0 | 0 |   |   |
1 | 1 |   |   |
2 | 2 |   |   |
3 |   | 0 |   |
4 |   | 1 |   |
5 |   |   | 'f' |
SELECT * FROM "Media" 
WHERE "MediaId" = $1 
AND ("AType" = 0 OR "BType" = 0 OR "C" is not null)

You should use is not null instead of !=null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM