问题
I have a similar question like this, but for PostgreSQL. I am using PostgreSQL 9.5.12 (x64) on my Windows 10 (x64) machine. I have a function (written in plpgsql) my_func() in database my_db. Is it possible to import/copy this function to another database in postgres?
回答1:
In psql the \ef command will open the function in an editor you can then save it to a file... unfortunately the UI of the windows version of psql was pretty cruddy last time I checked.
a pg_dump of the database with --schema-only will also include all function definitions. you can then open it in an editor and copy the functions.
回答2:
You could use pg_get_functiondef to get function definition as follows:
SELECT pg_get_functiondef(oid) AS definition FROM pg_proc WHERE proname = 'my_func';
来源:https://stackoverflow.com/questions/50646705/postgresql-copy-import-a-user-defined-function-from-one-database-to-another-dat