© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
2 replies
John

Question about writing database functions in plpgsql.

Hi I am new to plpqsql and hope to understand functions.

I currently have a function called
insert_document_contributor_by_update_documents
insert_document_contributor_by_update_documents
which is triggered, as the function states, by an update in the
documents
documents
table. This is the current version of the function.

begin
  insert into public.document_contributor(document_id, contributor)
  values(new.id, new.created_by);
  return new;
end
begin
  insert into public.document_contributor(document_id, contributor)
  values(new.id, new.created_by);
  return new;
end


But I want to check if the
document_contributor
document_contributor
table has an existing record with the match of
document_id
document_id
and
contributor
contributor
. Fyi, the
document_contributor
document_contributor
table is a join table that consists of only two columns stated above,
document_id
document_id
and
contributor
contributor
, and uses both of them as a composite primary key.

How do I add a condition and modify the function to my needs?
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Not writing to database in production
SupabaseSSupabase / help-and-questions
3y ago
Database Functions vs Edge Functions
SupabaseSSupabase / help-and-questions
5mo ago
Database Functions - Auth
SupabaseSSupabase / help-and-questions
4y ago
Notices for plpgsql
SupabaseSSupabase / help-and-questions
4y ago