Search code examples
postgresqlpgadminpg-dump

Create a new function from an existing function in Postgres?


I have created a function function_1() in Postgres.
Now I want to create another similar function function_2() and copy the content of function_1().

Any Postgres command line can do that?

So far I only used copy&paste method in the command line to create function_2() (need to change the function name to "function_2" after paste)


Solution

  • If you are using the GUI pgAdmin, you can simply select the function in the object browser and open the reverse engineered SQL script in an SQL editor window.

    There is a dedicated item in the options to automate it:

    Options - Query tool - Query Editor - Copy SQL from main window to query tool