473,785 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*******@postg resql.org

Nov 23 '05 #1
2 8604
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_databa se

Bye, Chris.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.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
2795
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 correct order to create the database. What is the syntax for executing script files from Transact-SQL?
2
5979
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 click on the VB script file which lies in a directory on the hard drive. Now I want to execute this file from a VB application or a Windows service. How do I call, reference or execute the file from VB.net?
6
1702
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 that you don't have to reference them within the (x)html document files.
2
265
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 entered by the user. best way? Thanks Jason
0
1399
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 attempting to run a DTS package from code it is because the local machine attempting to run the remote DTS package does not have the 'script file directory' defined on the local machine. Cheers
18
6720
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 I've already created on my computer. Whenever I go to open the script file (whose icon shows that it's a SQL Server Query File and I've got the file type set to open with SQLWB - SQL Server Management Studio), the file opens in Notepad instead of...
1
3110
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 that I could use this script in other pages. So I put a reference to the script file in the <head tag of the Master page. But that does not work because the <head tag of the Master page also contains a 'runat=server' statement. And only one <head...
2
1055
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 file.
1
2054
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 to now convert one of the shell script file to a perl file so I can use the in-built functions. Is the a way I can import the file with the globals and use them in my perl script? Thanks!
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.