Skip to content

Instantly share code, notes, and snippets.

@naranjja
Last active November 19, 2019 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naranjja/169b72251952ea5896b16dc29b49848a to your computer and use it in GitHub Desktop.
Save naranjja/169b72251952ea5896b16dc29b49848a to your computer and use it in GitHub Desktop.
create temp table user_info as
select A.*, B.sends_to_role
from users as A
left join role_plans as B on A.role_id = B.role_id
where 1 = 1
and (A.id = '{user_id}' or A.sap_id = '{user_id}')
and A.doc_id = '{doc_id}'
and A.is_active = true;
select A.id, A.name_1, A.surname_1, B."name" as company_name, B.id as company_id, A.role_id
from users as A
left join companies as B on A.company_id = B.id
where 1 = 1
and A.role_id in (select unnest(sends_to_role) from user_info)
and A.is_active = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment