It's a disaster that I, coming from MySQL and T-SQL, cannot figure out from documentation (0 real examples) and stackoverflow (0 real examples) how to deal with the most basic variable management in PostgreSQL.
Code below causes an error ERROR: duplicate declaration...
declare invalidThirdUser boolean := 'false';
invalidThirdUser = (select 'true' where NEW.sender_id not in(
select user1_id from thread where id = NEW.thread_id
union all
select user2_id from thread where id = NEW.thread_id
));
I tried
invalidThirdUser = (select...
invalidThirdUser := (select...
set invalidThirdUser = (select...
select invalidThirdUser = (select...
How painful is assigning a new value to variable in postgres? Thanks.
CREATEstatements of the table (paste the text, don't use images) and aDOblock where you declare and assign to the variable (dito). Instead of theDOblock a simple function definition would do to but is more complicated.trueandfalse, there's no need for the'which makes them actually string literals that get -- unnecessarily -- implicitly casted.new.sender_id NOT IN (...)is an expression that already evaluates to a Boolean value.