Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013

    Unanswered: Create global functions

    Is it possible to create a function for all databases on a server? We have the need to push this function(SQL) to all databases, there are several hundred of them, and would prefer not to have to push them to all the databases individually.

  2. #2
    Join Date
    Apr 2013
    As far as I know you can't create a function on a database engine level.

    All databases are created using predefined templates, and these templates have all the functions defined. So if you have several databases (not schema) you'd have to add the required functions to each db. And I don't see a problem here in case you're not planning to modify them every day. Just make a pgplsql script and run it several times using correspondent connections.

    If you add the functions to the mentioned templates ("template1" by default) all functions will be transferred to the new database automatically. Of course this doesn't solve the problem with existing databases, just the new ones.

    Normally in large projects multiple schema are used instead of multiple databases. In this case the problem can be solved using your own or public (preferably) namespace to declare your functions so every schema could see them.

    Also, just to get rid of any silly ideas that might come up, databases can't talk to each other without an external interface.
    Last edited by akaine; 04-12-13 at 19:33.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts