Unix Technical Forum

Re: Change Default Database

This is a discussion on Re: Change Default Database within the pgsql Sql forums, part of the PostgreSQL category; --> On 2/26/07, Rommel the iCeMAn <icecrew@gmail.com> wrote: > Hi list, > > I wrote a database creation script that ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 03:09 PM
=?ISO-8859-1?Q?Rodrigo_De_Le=F3n?=
 
Posts: n/a
Default Re: Change Default Database

On 2/26/07, Rommel the iCeMAn <icecrew@gmail.com> wrote:
> Hi list,
>
> I wrote a database creation script that begins with commands to drop the
> existing database (if it exists) and create it from scratch. These commands
> execute fine, the problem is that all subsequent commands are executed on
> the default database 'postgres'. What command can I use to set the default
> database to my newly created database (for the duration of the script)? SQL
> Server has a 'USE [dbname]' command, is there an equivalent command in
> PostgreSQL?
>
> Thanks in advance,
>
> Rommel Edwards
> Software Developer,
> Barbados, Caribbean.


If using psql:

\c dbname

then the rest of the commands.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 03:09 PM
Rommel the iCeMAn
 
Posts: n/a
Default Re: Change Default Database

Thanks for the swift responses,

I tried the \c command but I got the following error:

ERROR: syntax error at or near "\"
SQL state: 42601
Character: 520

Here's a code snippet ...

<snip>
--
-- TOC entry 1685 (class 1262 OID 16453)
-- Name: test_db; Type: DATABASE; Schema: -; Owner: postgres
--

DROP DATABASE IF EXISTS test_db;
CREATE DATABASE test_db WITH TEMPLATE = template0 ENCODING = 'UTF8';


ALTER DATABASE test_db OWNER TO postgres;

\c test_db; -- query tool doesn't like this command :-(

</snip>

Rommel Edwards
Software Developer,
Barbados, Caribbean.


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 03:09 PM
=?ISO-8859-1?Q?Rodrigo_De_Le=F3n?=
 
Posts: n/a
Default Re: Change Default Database

On 2/26/07, Rommel the iCeMAn <icecrew@gmail.com> wrote:
> Thanks for the swift responses,
>
> I tried the \c command but I got the following error:
>
> ERROR: syntax error at or near "\"
> SQL state: 42601
> Character: 520
>
> Here's a code snippet ...
>
> <snip>
> --
> -- TOC entry 1685 (class 1262 OID 16453)
> -- Name: test_db; Type: DATABASE; Schema: -; Owner: postgres
> --
>
> DROP DATABASE IF EXISTS test_db;
> CREATE DATABASE test_db WITH TEMPLATE = template0 ENCODING = 'UTF8';
>
>
> ALTER DATABASE test_db OWNER TO postgres;
>
> \c test_db; -- query tool doesn't like this command :-(
>
> </snip>
>
> Rommel Edwards
> Software Developer,
> Barbados, Caribbean.


\c only works in psql.

See:
http://www.postgresql.org/docs/8.2/static/app-psql.html

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

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 01:57 PM.


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