Skip to content

Instantly share code, notes, and snippets.

@ilhamsa1
Created August 28, 2020 09:38
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 ilhamsa1/01924bfc40dcd4a4eb5674bb9e5c86dd to your computer and use it in GitHub Desktop.
Save ilhamsa1/01924bfc40dcd4a4eb5674bb9e5c86dd to your computer and use it in GitHub Desktop.
sample function sql query
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