© 2026 Hedgehog Software, LLC

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

Foreign Key Array Columns

Hi, I'm having trouble understanding or finding resources on columns of foreign key arrays. Say I have a post that people can comment on. So, I would think that I could add an array of the primary id's of comments to a post. However, this would run 2 dabatase functions (one to create each comment and the other to add the comments primary id to the post). The alternative would be to add the primary id of the post to the comment (and get rid of the comment array in the post). However, this method would require 2 database functions to obtain all of the data from a post (one to get the post itself and one to query all comments with the appropriate post id (as opposed to the first method which would require only one query with joins)). Is there a better way, where it only requires 1 database function to create the comment and 1 database function to get the post with its comments? If not, which method (1st or 2nd) is more popular or would you recommend? Thanks in advance!
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

Composite key foreign key issue
SupabaseSSupabase / help-and-questions
6mo ago
array of foreign keys
SupabaseSSupabase / help-and-questions
4y ago
violates foreign key constraint
SupabaseSSupabase / help-and-questions
4y ago
Foreign Key Fails on Trigger
SupabaseSSupabase / help-and-questions
4y ago