Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Interfacing with PostgreSQL

by aijin (Monk)
on Jul 11, 2001 at 18:58 UTC ( #95707=perlquestion: print w/replies, xml ) Need Help??
aijin has asked for the wisdom of the Perl Monks concerning the following question:

I've gotten access to a PostgreSQL database on a friend's server recently, and I'd love to start playing around with it in Perl.

There aren't any modules installed to deal with this DB, but all I have to do is ask, and my friend will install whatever I desire. I'm rather inexperienced with using Perl to access databases, however, so I'm looking for advice on which module to use to interface with the database and why it's better than the others...IYHO of course.

Replies are listed 'Best First'.
Re: Interfacing with PostgreSQL
by rob_au (Abbot) on Jul 11, 2001 at 19:23 UTC
    There aren't any modules installed to deal with this DB
    There is a DBD module for PostgreSQL which allows you to interface this database via the ubiquitous DBI module. In addition to this, given the widespread use of this (DBI) interface (and module) there are many examples and references available in both online and print format.
    You might want to start by looking here and here.

    Ooohhh, Rob no beer function well without!
Re: Interfacing with PostgreSQL
by bschmer (Friar) on Jul 11, 2001 at 19:23 UTC
    PostgreSQL has an RPM on their web site that contains the Pg PM that is needed to talk to the backend. There is also test code that you can use as a base from which to start your script(s). I haven't done anything with DBI, so I don't know if you can use it, but I'm not terribly displeased with the interface provided by Pg.

    Your milage may vary since I was a DB guy back in the early 90's and just about any scripting interface is better than what I had available to me back then ;-).

Re: Interfacing with PostgreSQL
by lestrrat (Deacon) on Jul 11, 2001 at 22:14 UTC

    I definitely would suggest using DBI and DBD::Pg rather than the Pg module that comes with Postgres.

    I've used both, and while gives you more of a straight forward approach with reagard to the Postgres API, DBI is so much nicer to use. I have to say, DBI is a pretty damn well thought out general database interface.

    Plus it seems that on some very specific installations, barfs when it comes to large objects. :-(

    Anyway, you will need the Postgres source to compile DBD::Pg. So get the tar ball, rather than the binary...

      No, no, compiling DBD::Pg only requires the header files and libpq. All of them are bundled inside postgresql-devel rpm. Complete source files aren't necessary.
(ichimunki) Re: Interfacing with PostgreSQL
by ichimunki (Priest) on Jul 11, 2001 at 20:25 UTC
    If you are going to "make" the DBD::Pg module from source, you may need to get a copy of the postgreSQL source code from IIRC, the modules depends on the libs and includes-- even requiring you to set environment variables! So much for perl -MCPAN -e "shell install DBD::Pg". :)

    There is also an excellent book on postgreSQL which used to be in PDF but is now available on the web using HTML. While most of the book is devoted to the DBMS itself and is very good, the chapter on the Perl bindings is pitiful.

    But using DBI and DBD::Pg, you will likely find the perldoc for each of these to be informative.

      Several years later . . .

      The book to which you linked has moved. It is now available here.

      I post this in case others who come later might be searching for similar information and disappointed at the broken link. Also, in case the location should change again, the title of the book is PostgreSQL: Introduction and Concepts, and its author's name is Bruce Momjian. It dates back to 2000, though. There are newer books available, if you're willing to shell out the cash.

      print substr("Just another Perl hacker", 0, -2);
      - apotheon
      CopyWrite Chad Perrin

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://95707]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2018-06-24 11:10 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.