Unix Technical Forum

Install scripts?

This is a discussion on Install scripts? within the Pgsql General forums, part of the PostgreSQL category; --> Rookie question... I'm converting a MySQL database to Postgre. In MySQL, all the tables are defined in seprate 'table_name.sql' ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 08:47 PM
Charl Gerber
 
Posts: n/a
Default Install scripts?

Rookie question... I'm converting a MySQL database to Postgre. In MySQL,
all the tables are defined in seprate 'table_name.sql' file.

There is one 'install.sql' file which does something like:

DROP DATABASE db_name IF EXISTS (<--- is there something similar in
Postgre? Like the CREATE OR REPLACE FUNCTION)

CREATE DATABASE db_name;

USE db_name;

SOURCE users.sql;
SOURCE teams.sql;
SOURCE players.sql;

etc.

Using the mysql command like tool, you just run "source install.sql"
and the whole database is loaded.

How do you do this with Postgre? I tried using the "insert filename"
command, but one file cannot seem to load another (ie, a SELECT filename
gives me an error) and to start with, I cannot find something similar to
"USE DATABASE" ....

Thanks!



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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 08:47 PM
Peter Eisentraut
 
Posts: n/a
Default Re: Install scripts?

Charl Gerber wrote:
> DROP DATABASE db_name IF EXISTS (<--- is there something similar in
> Postgre? Like the CREATE OR REPLACE FUNCTION)


No, you just go ahead and ignore the error.

> CREATE DATABASE db_name;
>
> USE db_name;


\connect db_name

> SOURCE users.sql;


\i users.sql

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 08:47 PM
Tom Lane
 
Posts: n/a
Default Re: Install scripts?

Charl Gerber <cpger@xs4all.nl> writes:
> There is one 'install.sql' file which does something like:


> DROP DATABASE db_name IF EXISTS (<--- is there something similar in
> Postgre? Like the CREATE OR REPLACE FUNCTION)


> CREATE DATABASE db_name;


There's no IF EXISTS. Usually people just do a DROP and ignore the
error if any.

> How do you do this with Postgre? I tried using the "insert filename"
> command, but one file cannot seem to load another (ie, a SELECT filename
> gives me an error) and to start with, I cannot find something similar to
> "USE DATABASE" ....


You probably want to be looking at psql's \i and \c commands,
respectively. Does "insert foo" really mean a file inclusion
command in MySQL? Bizarre ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:08 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com