Create or replace function creating duplicate

Hey, When deploying an update of a function via SQL ('CREATE OR REPLACE FUNCTION my_function'), it no longer replaces the function. Instead, it creates a duplicate function with the same name. Does anyone know if this is an intentional change by Supabase? Or a bug? Thank you.
5 Replies
silentworks
silentworks3w ago
Show a screenshot of this please. This is a Postgres thing and it doesn't create duplicates if the function already exists. If the Supabase UI is showing that then there might be a bug in your setup. I just tested this on my own Supabase project and don't have any duplicates
silentworks
silentworks3w ago
Here is a screen recording demonstrating this
garyaustin
garyaustin3w ago
If you create or replace a function with different parameters or return it will create a new function with the same name and those parameters.
This is the way Postgres works. You have to drop the function and create a new one if you don't want the old one.
vick
vick3w ago
This is how postgres implements polymorphism and is quite useful to have a function of the same name that can operate on strings and integers (for example) and "do the right thing" by having multiple implementations.
ambientexplorerturbo
Thanks for your insights. Knowing that Postgres is intentionally designed to handle multiple functions with the same name (but with different arguments) was an important lesson. On reflection, I realised that my earlier functions didn't use arguments, so these were replaced and bypassed polymorphism and duplicate functions. I love that the polymorphism means I won't experience breaking changes when adding additional arguments to fucntions. Very cool. Thank you. :solved: Solved

Did you find this page helpful?