Re: Porting Code to Postgresql

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Errol Neal <sysadmins(at)enhtech(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Porting Code to Postgresql
Date: 2003-10-15 18:44:55
Message-ID: Pine.LNX.4.33.0310151242150.23561-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 15 Oct 2003, Errol Neal wrote:

> Hi all,
>
> Not sure if this is a question for a php list or this one, but I'll give it
> a shot and
> if I am wrong, please do not crucify me. :-)
>
> There is a php based sourceforge project called mailwatch.
> (http://www.sourceforge.net/projects/mailwatch) It logs data from the excellent
> Mailscanner security product into a mysql database. Now, I am not a php
> programmer,
> and I am barely a Postgres DBA, but I would really like to port the code to
> Postgresql.
> I have my trust Postgresql Book which covers the API for Postgresql and the
> PHP statements
> used for Postgresql seem almost identical to those used for Mysql. I
> understand that there are
> some slight differences in the data types supported by Mysql and
> Postgresql, however are the differences
> between the two Databases and API's that great to make task impossible for
> an unexperienced person
> such as myself? We currently use Postgresql in conjunction with sendmail to
> store our access, mailertable
> and other db's, so it would be very convenient for us to achieve this.

The issues you're likely to hit are twofold:

The first is that MySQL silently accepts that which postgresql may reject.
Look for errors on insert when this happens. for example, in postgresql,
you use the SQL keyword DEFAULT when inserting an autoincrement field, or
leave it out of your list of inserted fields. In MySQL you insert,
counterintuitively, a NULL to do the same thing.

The second is the lack of a mysql_last_id type function. While you can
get the last OID of an insert in postgresql, this is discouraged, as OIDs
may or may not exist for a given table depending on how it was declared.
Tis better to use the currval() / nextval() functions for such things.

All the rest if pretty straight forward hacking, having converted or
helped to convert a few other MySQL tools to Postgresql recently.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alejandro Forero Cuervo 2003-10-15 18:53:49 Re: Getting error codes for failed queries?
Previous Message Andrew Sullivan 2003-10-15 18:44:09 Re: constant time count(*) ?