[英]Insert into table
I want always to insert into mylog
table regardless whether user exists in myusers
table or not, so I'm using: 无论用户是否存在于
myusers
表中,我总是希望插入到mylog
表中,因此我正在使用:
insert into mylog (c1,c2)
select t.userx, coalesce(ig.webuser,'X') from (
select 1,1,'username'::text as userx
) as t
left join myusers ig on t.userx = ig.webuser
;
Is there shorter query which does same thing? 有做相同事情的较短查询吗?
The statement 该声明
INSERT INTO mylog (c1,c2)
VALUES('username', coalesce((SELECT webuser
FROM myusers
WHERE webuser='username'),'X'));
would do the same but shorter. 会做同样的事情,但是会更短。 imo your statement makes no sense.
imo你的陈述没有道理。 You always log 'username','X' or 'username','username'
您始终记录“用户名”,“ X”或“用户名”,“用户名”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.