Executing script file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tumurbaatar S.

    Executing script file

    Hi!
    I cannot imagine how to create db from a script file and execute
    other DDL statements on this new db.
    Currently I use 'psql -f file' to perform all needed DDL statements
    except of create db. Because when I insert 'CREATE DATABASE'
    at the beginning of the script, the server creates a db but following
    commands like 'CREATE TABLE' and etc run on the current db, i.e.
    not in context of newly created db. Any ideas?

    P.S. Some RDBMS automatically switches to a newly created db
    after 'CREATE DATABASE' and some other languages have command
    like 'USE' to switch to a different db.


    ---------------------------(end of broadcast)---------------------------
    TIP 1: subscribe and unsubscribe commands go to majordomo@postg resql.org

  • Richard Huxton

    #2
    Re: Executing script file

    On Tuesday 13 April 2004 08:40, Tumurbaatar S. wrote:[color=blue]
    > Hi!
    > I cannot imagine how to create db from a script file and execute
    > other DDL statements on this new db.[/color]
    [color=blue]
    > P.S. Some RDBMS automatically switches to a newly created db
    > after 'CREATE DATABASE' and some other languages have command
    > like 'USE' to switch to a different db.[/color]

    You want to look into the "\c" command available in psql. That reconnects to a
    different db / user.

    Worth doing a pg_dump (text format) and looking at its output (or pg_restore
    to a text-file).

    --
    Richard Huxton
    Archonet Ltd

    ---------------------------(end of broadcast)---------------------------
    TIP 6: Have you searched our list archives?



    Comment

    • Chris

      #3
      Re: Executing script file

      [color=blue]
      > Currently I use 'psql -f file' to perform all needed DDL statements
      > except of create db. Because when I insert 'CREATE DATABASE'
      > at the beginning of the script, the server creates a db but following
      > commands like 'CREATE TABLE' and etc run on the current db, i.e.
      > not in context of newly created db. Any ideas?[/color]

      Use \c, like this:

      \c your_new_databa se

      Bye, Chris.



      ---------------------------(end of broadcast)---------------------------
      TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@postg resql.org so that your
      message can get through to the mailing list cleanly

      Comment

      Working...