I have this select
insert into test(t_name)
(select users.first_name || '_' || users.last_name
|| '_' || to_date($values.report_date, 'YYYY.MM.DD')
from users where users.id = $session.user_id)
which works as supposed, except I want it if users.first_name/users.last_name are null and user_id=0 to insert another string ‘admin’ otherwise I get error because it violates not-null constraint on column t_name.
Any suggestions are appreciated. Thanks.
Use a CASE in the SELECT part:
It’s not clear (to me) from the question if all conditions you mentioned have to be true or just one of them. Depending on what you want, you should change the
ANDs toORs in the firstWHENpart.(Note that there is no need to enclose the SELECT in
()for anINSERT ... SELECTstatement)