matth
05/26/2023, 5:49 PMcreate or replace function migrate_contact_roles() returns setof test_contact_roles as $$
declare
d_roles text[] := array[]::text[];
d_id int;
d_acct boolean;
str_acct text = "acct";
begin
-- lookup 1 contact
select
id, is_acct into d_id, d_acct
from test_contact_roles where id = 1;
if (d_acct) then
d_roles := d_roles || str_acct;
end if;
update test_contact_roles set roles = d_roles where id = d_id;
return query select * from get_contacts()
where id = 1;
end;
$$ language plpgsql;
When I run the function I'm getting the following error
> Failed to run sql query: column "acct" does not exist
Any help or suggestions greatly appreciated! Thank you
https://cdn.discordapp.com/attachments/1111712651182092289/1111712651295326279/Screenshot_2023-05-26_at_12.38.16_PM.png▾
https://cdn.discordapp.com/attachments/1111712651182092289/1111712651567976549/Screenshot_2023-05-26_at_12.38.51_PM.png▾
matth
05/26/2023, 5:50 PMmatth
05/26/2023, 6:11 PMstr_acct
has to be single quotes.matth
05/26/2023, 6:11 PMvick
05/26/2023, 6:41 PMsql
update test_contact_roles set roles = array_append(roles,'acct') where is_acct;
vick
05/26/2023, 6:42 PMmatth
05/26/2023, 6:50 PMvick
05/26/2023, 6:51 PMmatth
05/26/2023, 6:52 PMmatth
05/26/2023, 6:53 PMvick
05/26/2023, 6:53 PMsql
begin;
update ....;
-- select rows to inspect it did what you want
commit;
vick
05/26/2023, 6:53 PMpsql
command line to connect to the postgres server URI directly.matth
05/26/2023, 6:57 PMvick
05/26/2023, 6:58 PMvick
05/26/2023, 6:58 PMmatth
05/26/2023, 6:58 PMvick
05/26/2023, 6:59 PMmatth
05/26/2023, 7:00 PMvick
05/26/2023, 7:01 PMselect * from test_contact_roles where roles is null
vick
05/26/2023, 7:02 PMmatth
05/26/2023, 7:03 PMvick
05/26/2023, 7:04 PMmatth
05/26/2023, 7:05 PM