Re: Re: PostreSQL SQL for MySQL SQL

From: John Burski <John(dot)Burski(at)911ep(dot)com>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: PostreSQL SQL for MySQL SQL
Date: 2001-02-06 19:10:21
Message-ID: 3A804C1D.7681637@911ep.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mitch Vincent wrote:

> > I'm fairly new to PostreSQL, coming from MySQL. My Python application
> > generates these MySQL commands:
> >
> > drop database if exists Foo;
> > create database Foo;
> > use Foo;
> > Using the PostgreSQL online docs, my closest translation is:
> >
> > drop database Foo;
> > create database Foo;
>
> You supply the database name on connect.. I don't *think* you can change
> databases after you've connected but I could be very wrong (if you can, I'd
> sure like to know!)

If you're running PostgreSQL interactively (via the "psql" command) you can
connect to any database in the installation, provided the user in question has
been granted rights to access the database, by using the "\connect" command.
The format is "\connect dbname".

>
>
> > What I'm missing is:
> > * "if exists" for the drop, in order to avoid an error the very first time
> > this program runs
> > * the "use Foo;"
> >
> > Can I do these things in PostreSQL from SQL (e.g., not from the command
> line)?
>
> Not sure on these...

There is no "if exists" functionality in PostgreSQL. However, you could
probably create your own "if exists" type of functionality. I've found that
it's not really necessary. I access my databases either interactively, via
psql, via the Perl Pg module, or via PHP. If you attempt to drop a database
that doesn't exist, PostgreSQL will issue an error message. If you're running
interactively, you'll see the message; if you're accessing via a Perl module or
PHP, you can check the query results to see if an error occurred. I'm fairly
certain that this same mechanism exists if you're using C or C++ to access your
databases.

I'm not familiar with the "use Foo" functionality of MySQL, so I can't discuss
it.

>
>
> -Mitch

--
John Burski
Chief IT Cook and Bottlewasher
911 Emergency Products, St. Cloud, MN
(320) 656 0076 www.911ep.com

++++++++++++++++++++++++++++++++++
+ How's your cheese holding out? +
++++++++++++++++++++++++++++++++++

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthew 2001-02-06 19:15:04 RE: Re: startup Postgres on NT
Previous Message Brett W. McCoy 2001-02-06 18:42:22 Re: Re: PostreSQL SQL for MySQL SQL