Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Location
    Grenoble, France
    Posts
    4

    Unanswered: drop database if exists

    I would like to use some kind of "drop database if exists" feature. (Like in MySQL and other databases.)
    - I tried to use a PlPgsql function but it isn't possible to drop a database from a function !
    - I saw some discussions on lists that indicates it could be in development

    I didn't find a solution to do this !

    Thanks
    Bruno

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Quote Originally Posted by bruno.vernay
    I would like to use some kind of "drop database if exists" feature. (Like in MySQL and other databases.)
    - I tried to use a PlPgsql function but it isn't possible to drop a database from a function !
    - I saw some discussions on lists that indicates it could be in development

    I didn't find a solution to do this !

    Thanks
    Bruno
    Are you sure you're not trying to drop a database to which you are currently connected?

    Now, I've never tried anything like this, but presumably, you could write your own function in c, which would shell execute the utility program dropdb.

    I DO have a question about this, though. Why would you want to drop a database programatically? This is a pretty drastic step (and an irrevocable one) to take; normally, you want to have human interaction on something so final.
    Last edited by loquin; 08-02-06 at 15:56.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Apr 2003
    Location
    Grenoble, France
    Posts
    4
    It is for test scripts. Since I cannot be sure where the previous tests finished, I don't know if the database exist or not.

  4. #4
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    BTW.

    You can determine if the database exists by interrogating

    pg_catalog.pg_database

    ref http://www.xtremevbtalk.com/showthread.php?t=268727

    One last question/comment. You say you aren't able to drop a database from within a function. You cartainly cannot drop a database to which ANYONE is connected (including yourself.) However, you may, repeat may be able to drop a different database than the one to which you are logged on from within a function. In other words, try creating a function in database2 to drop database1...
    Last edited by loquin; 08-16-06 at 14:25.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

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