Created
August 28, 2020 09:38
-
-
Save ilhamsa1/01924bfc40dcd4a4eb5674bb9e5c86dd to your computer and use it in GitHub Desktop.
sample function sql query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION lawkin.create_person_agent_func ( | |
sub_id uuid, | |
first_name varchar, | |
last_name varchar, | |
email varchar, | |
phone_number varchar, | |
country varchar, | |
practice_since varchar, | |
profesional_qualification text, | |
agent_type_id uuid, | |
institutional_id uuid, | |
bio text, | |
title text, | |
is_supervisor boolean, | |
is_blocked boolean, | |
is_profile_publish boolean, | |
preferred_payout_method varchar | |
) | |
RETURNS lawkin.agent_profile | |
LANGUAGE plpgsql | |
AS $agent$ | |
DECLARE | |
person lawkin.person; | |
agent lawkin.agent_profile; | |
-- created_sub uuid; | |
-- username uuid; | |
-- tokenAccess text; | |
BEGIN | |
INSERT INTO lawkin.person(sub, email, given_name, family_name, phone_number) VALUES( | |
sub_id, email, first_name, last_name, phone_number | |
) returning * into person; | |
-- SELECT sub INTO created_sub FROM lawkin.person WHERE person.sub LIKE sub_id; | |
INSERT INTO lawkin.agent_profile( | |
country, | |
practice_since, | |
profesional_qualification, | |
bio, | |
phone_number, | |
title, | |
is_supervisor, | |
is_blocked, | |
is_profile_publish, | |
preferred_payout_method, | |
person_id, | |
agent_type_id, | |
institutional_id, | |
created_at | |
) VALUES ( | |
country, | |
practice_since, | |
profesional_qualification, | |
bio, | |
phone_number, | |
title, | |
is_supervisor, | |
is_blocked, | |
is_profile_publish, | |
preferred_payout_method, | |
person.id, | |
agent_type_id, | |
institutional_id, | |
current_timestamp | |
) returning * into agent; | |
return agent; | |
END; | |
$agent$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment