postgresql postgres 中的 sqlite IFNULL()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43934155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sqlite IFNULL() in postgres
提问by RagnarLodbrok
What is the equivalent of SQLite's IFNULL()
in Postgres?
IFNULL()
Postgres中 SQLite 的等价物是什么?
I have to following query (sqlite in Ruby):
我必须遵循查询(Ruby 中的 sqlite):
SELECT ifnull(max(code_id) + 1, 1)
FROM configentries
WHERE configtable_id = ...
How should this look like if I want the same result with PostgreSQL?
如果我想要与 PostgreSQL 相同的结果,这应该如何?
回答by Vao Tsun
回答by rurugg
Try this, Select NULLIF(Max(code_id), 0) +1 from configentries WHERE configtable_id = ...
试试这个,选择 NULLIF(Max(code_id), 0) +1 from configentries WHERE configtable_id = ...