473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 ma*******@postgresql.org

Nov 23 '05 #1
2 8583
On Tuesday 13 April 2004 08:40, Tumurbaatar S. wrote:
Hi!
I cannot imagine how to create db from a script file and execute
other DDL statements on this new db. 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.


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?

http://archives.postgresql.org

Nov 23 '05 #2
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?


Use \c, like this:

\c your_new_database

Bye, Chris.

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

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil | last post by:
Hi, I have my create statments for tables, procedures, views, etc in individual Transact-SQL script files (.sql). I wnat to write another script file that executes these scripts in the...
2
by: J. Kingsley | last post by:
I am loading XML data into a SQL Server database using SQLXML with bulkload. I use a VB script file to perorm the load with the map schemas and the XML files. To do the load manually, you just double...
6
by: Mellow Crow | last post by:
Just discovered this technique. Is this old hat? Would there be any disadvantage to doing this? In your external .js file: /* Summary: includes external scripts in this external script so...
2
by: Jason | last post by:
Hi I would like to create a .NET app that can receive an SQL script file as input. it will take the script file and execute it on the database, depending on what connection properties were...
0
by: Ollie Riches | last post by:
I am executing a DTS programmatically from C# using COM interop. Is it possible to set the 'script file directory' from the C# code? For anyone else you gets an 'Access Denied Error' when...
18
by: mollyf | last post by:
I just installed SQL Server 2005 on my PC (the developer's edition) yesterday. I have some scripts written by one of my coworkers to create some tables and stored procedures in a database that...
1
by: Larry Rebich | last post by:
I'm using some Java Script I found that supports a 'back' button on my ASP.Net page. The Asp.Net page uses a Master page. I thought I'd put the Java Script in a Java Script file . The thought was...
2
by: Sheena777 | last post by:
how do you pass parameters to a script file? I want to pass values from a vb.net textbox to vb script file. The whole point of this is to be able to run the validation of the control from the script...
1
by: looza | last post by:
Hi All, I have a bunch of shell script files that use a common shell script file that contains certain global variables that are declared and initialized or derived by some arithmatic. I have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.