I want always to insert into mylog
table regardless whether user exists in myusers
table or not, so I'm using:
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. You always log 'username','X' or 'username','username'
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.