Перейти к содержанию

ensure_user

Сигнатура: ensure_user("p_tg_user_id" bigint, "p_tg_username" "text") RETURNS "public"."users"
Язык: sql
Security: DEFINER

Тело функции

declare u public.users;
begin
  insert into public.users (tg_user_id, tg_username)
  values (p_tg_user_id, p_tg_username)
  on conflict (tg_user_id) do update set tg_username = excluded.tg_username
  returning * into u;

  insert into public.wallets (user_id)
  values (u.id)
  on conflict (user_id) do nothing;

  return u;
end;