Sql orgot删除括号。这对我有用。谢谢是否有方法引发异常,使其不检查userid=xxx位,而只检查禁用的\u til>yyy位?如果用户ID不存在,我的应用程序中会有不同的流。我只想根据禁用的值抛出异常。否则会发生正常的异常。@a_horse_,没有名字:
Sql orgot删除括号。这对我有用。谢谢是否有方法引发异常,使其不检查userid=xxx位,而只检查禁用的\u til>yyy位?如果用户ID不存在,我的应用程序中会有不同的流。我只想根据禁用的值抛出异常。否则会发生正常的异常。@a_horse_,没有名字:,sql,postgresql,if-statement,sql-insert,Sql,Postgresql,If Statement,Sql Insert,orgot删除括号。这对我有用。谢谢是否有方法引发异常,使其不检查userid=xxx位,而只检查禁用的\u til>yyy位?如果用户ID不存在,我的应用程序中会有不同的流。我只想根据禁用的值抛出异常。否则会发生正常的异常。@a_horse_,没有名字:真的,谢谢。忘记去掉括号了。 If (select banned_till from users where userid = $1) = nil or < currentTime Insert in posts (col1, co
orgot删除括号。这对我有用。谢谢是否有方法引发异常,使其不检查userid=xxx位,而只检查禁用的\u til>yyy位?如果用户ID不存在,我的应用程序中会有不同的流。我只想根据禁用的值抛出异常。否则会发生正常的异常。@a_horse_,没有名字:真的,谢谢。忘记去掉括号了。
If (select banned_till from users where userid = $1) = nil or < currentTime
Insert in posts (col1, col2) values ('abc', 'xyz')
ELSE
RAISE Exception "User is banned"
ENDIF
DO
$$
BEGIN
IF (select banned_till from users where unqid = 'user01') < now() THEN
RAISE EXCEPTION 'User is banned';
ELSE
insert into posts (unqid, title, link, content, author_id, author_nick, author_flair)
SELECT 'pid03', 'Sample post title', 'www.google.com', 'This is a sample Post Content', unqid, nickname, flair
from users where unqid = 'user01';
END IF;
END
$$;
INSERT INTO posts (col1, col2)
SELECT 'abc', 'xyz'
FROM users
WHERE userid = $1 -- assuming userid is UNIQUE
AND (banned_till >= currentTime) IS NOT TRUE;
DO
$$
BEGIN
INSERT INTO posts (col1, col2)
SELECT 'abc', 'xyz'
FROM users
WHERE userid = $1
AND (banned_till >= currentTime) IS NOT TRUE;
IF NOT FOUND THEN
RAISE EXCEPTION 'User is banned';
END IF;
END
$$;
with s as (
select banned_till
from users where userid = $1
),
i as (
insert into posts (col1, col2)
select v.col1, v.col2
from (values ('abc', 'xyz')) v(col1, col2)
where (select coalesce(max(banned_till), current_date) from s) < now()
)
select max( coalesce(max(banned_till), current_date) ) < current_time as is_success
from s;