Thread: Postgres and Perl: Which DBI module?
hello, I just managed to get a simple database running with postgresql. Now I would like to write some CGI scripts in perl that will be able to use it. What perl module should I use for this? I have found something called DBI ... and found examples for CSV databases ... but I am curious what module I should use for postgres ... Is there a DBI::Postgres module like DBI::CSV ? Cheers, Jim
I just 'use DBI;' at the top of my scripts and my $dbh = DBI->connect('DBI:Pg:dbname=mydb', 'myuser', '',{RaiseError => 1,AutoCommit => 0})||&quit_unlogged('Could not connect to DB'); to connect. Obviously, dbname, options and what to do if connection fails will be different. On Saturday 27 July 2002 6:02 pm, you wrote: > hello, > > I just managed to get a simple database running with postgresql. > > Now I would like to write some CGI scripts in perl that will be able to > use it. > > What perl module should I use for this? > > I have found something called DBI ... and found examples for CSV > databases ... but I am curious what module I should use for postgres ... > > Is there a DBI::Postgres module like DBI::CSV ? > > Cheers, > Jim
> hello, > > I just managed to get a simple database running with postgresql. > > Now I would like to write some CGI scripts in perl that will be able to > use it. > > What perl module should I use for this? I succesfully used the module called Pg: http://www.cpan.org/modules/by-module/Pg/pgsql_perl5-1.9.0.tar.gz Cheers -------- François Home page: http://www.monpetitcoin.com/ "A fox is a wolf who sends flowers"
On Saturday 27 Jul 2002 7:02 pm, jgdon wrote: > hello, > > I just managed to get a simple database running with postgresql. > What perl module should I use for this? > I have found something called DBI ... and found examples for CSV > databases ... but I am curious what module I should use for postgres ... > > Is there a DBI::Postgres module like DBI::CSV ? There are two parts to this puzzle. The DBI module is a framework and you plug in DBD modules for each database. Check search.cpan.org for details. - Richard Huxton
On 29/7/02 at 14:48, dba@paragraf.ch (Francois Suter) wrote: > > hello, > > > > I just managed to get a simple database running with postgresql. > > > > Now I would like to write some CGI scripts in perl that will be able > to > > use it. > > > > What perl module should I use for this? > > I succesfully used the module called Pg: I d/l'd DBD::Pg using CPAN but the Makefile.PL complained that the env vars `POSTGRES_INCLUDE' and `POSTGRES_LIB' couldn'tbe found so that `libq.so' couldn't be located. Are `POSTGRES_INCLUDE' and `POSTGRES_LIB' set in your $PATH? Any ideas appreciated :-) Regards, Phil.
On Fri, 2 Aug 2002, Phil Dobbin wrote: > On 29/7/02 at 14:48, dba@paragraf.ch (Francois Suter) wrote: > > > > hello, > > > > > > I just managed to get a simple database running with postgresql. > > > > > > Now I would like to write some CGI scripts in perl that will be able > > to > > > use it. > > > > > > What perl module should I use for this? > > > > I succesfully used the module called Pg: > > I d/l'd DBD::Pg using CPAN but the Makefile.PL complained that the env vars `POSTGRES_INCLUDE' and `POSTGRES_LIB' couldn'tbe found so that `libq.so' couldn't be located. > > Are `POSTGRES_INCLUDE' and `POSTGRES_LIB' set in your $PATH? > > Any ideas appreciated :-) Define these variables :-) in bash: export POSTGRES_INCLUDE=/usr/local/pgsql/include export POSTGRES_LIB=/usr/local/pgsql/lib tcshL setenv POSTGRES_INCLUDE /usr/local/pgsql/include setenv POSTGRES_LIB /usr/local/pgsql/lib > > Regards, > > Phil. > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org > Regards, Oleg _____________________________________________________________ Oleg Bartunov, sci.researcher, hostmaster of AstroNet, Sternberg Astronomical Institute, Moscow University (Russia) Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(095)939-16-83, +007(095)939-23-83
On 2/8/02 at 17:36, oleg@sai.msu.su (Oleg Bartunov) wrote: > On Fri, 2 Aug 2002, Phil Dobbin wrote: > > > On 29/7/02 at 14:48, dba@paragraf.ch (Francois Suter) wrote: > > > I succesfully used the module called Pg: > > > > I d/l'd DBD::Pg using CPAN but the Makefile.PL complained that the > env vars `POSTGRES_INCLUDE' and `POSTGRES_LIB' couldn't be found so > that `libq.so' couldn't be located. > > > > Are `POSTGRES_INCLUDE' and `POSTGRES_LIB' set in your $PATH? > > > > Any ideas appreciated :-) > > Define these variables :-) > > in bash: > export POSTGRES_INCLUDE=/usr/local/pgsql/include > export POSTGRES_LIB=/usr/local/pgsql/lib Thanks for that. It worked fine. I had followed the instructions in the pgsql O'Reilly book (pp.25) and they didn't lookright. That looked a lot better :-) Regards, Phil.
On 2/8/02 at 10:00, smvfp@mail.smvfp.com (Leland F. Jackson, CPA) wrote: > Hi Phil, [snip] > If you already have Pg.pm on your system, which I suspect that you do, > then > it is a matter of refering to it correctly in your perl script or you > could > copy Pg.pm to a driectory included in the @INC array. There is no DBD::Pg @INC. I checked: `perl MDBD::Pg -e l' which returned the usual 'can't locate...'. > I hope I havn't confused you Not at all. Thanks for your input :-) Perl's my strong suit, it's Postgres that I'm new at ;-) I'm running Perl 5.8.0 on Mac OS X 10.1.5 which required a lot of modules to be re-installed for 5.8.0 to install. So, I'min the middle of swapping from MySQL -> PostgreSQL and having recompile Perl mods too. Regards, Phil. > ----- Original Message ----- > From: "Phil Dobbin" <phildobbin@pobox.com> > To: "Francois Suter" <dba@paragraf.ch> > Cc: <pgsql-general@postgresql.org> > Sent: Friday, August 02, 2002 9:18 AM > Subject: Re: [GENERAL] Postgres and Perl: Which DBI module? > > > > On 29/7/02 at 14:48, dba@paragraf.ch (Francois Suter) wrote: > > > > > > hello, > > > > > > > > I just managed to get a simple database running with postgresql. > > > > > > > > Now I would like to write some CGI scripts in perl that will be > able > > > to > > > > use it. > > > > > > > > What perl module should I use for this? > > > > > > I succesfully used the module called Pg: > > > > I d/l'd DBD::Pg using CPAN but the Makefile.PL complained that the > env > vars `POSTGRES_INCLUDE' and `POSTGRES_LIB' couldn't be found so that > `libq.so' couldn't be located. > > > > Are `POSTGRES_INCLUDE' and `POSTGRES_LIB' set in your $PATH? > > > > Any ideas appreciated :-) > > > > Regards, > > > > Phil. > > > > ---------------------------(end of > broadcast)--------------------------- > > TIP 1: subscribe and unsubscribe commands go to > majordomo@postgresql.org >
Around 15:36, +0100 Oleg Bartunov oleg@sai.msu.su wrote: >On Fri, 2 Aug 2002, Phil Dobbin wrote: > >> On 29/7/02 at 14:48, dba@paragraf.ch (Francois Suter) wrote: [snip] >> > I succesfully used the module called Pg: >> >> I d/l'd DBD::Pg using CPAN but the Makefile.PL complained that the env >vars `POSTGRES_INCLUDE' and `POSTGRES_LIB' couldn't be found so that >`libq.so' couldn't be located. >> >> Are `POSTGRES_INCLUDE' and `POSTGRES_LIB' set in your $PATH? >> >> Any ideas appreciated :-) > >Define these variables :-) > >in bash: >export POSTGRES_INCLUDE=/usr/local/pgsql/include >export POSTGRES_LIB=/usr/local/pgsql/lib That makes sense :-) I followed the example in the O'Reilly book (pp.25) and it didn't look right. This does, however. Many thanks, Regards, Phil.
On Fri, 2002-08-02 at 10:43, Phil Dobbin wrote: > That makes sense :-) I followed the example in the O'Reilly book (pp.25) > and it didn't look right. This does, however. For future reference: IIRC the instruction in that book are for installing the Pg module, which is a low level wrapper to libpq and NOT a DBI module. If you're wondering what it has over DBI... just a more verbose and closer to libpq syntax. Unlike some low level drivers I don't think this one gives any finer control than you can get with the DBD:Pg one (it's a wrapper for libpq as well). I'd personally suggest DBI for the consistant interface across DBMSs.
Around 23:01, +0100 Arguile arguile@lucentstudios.com wrote: >On Fri, 2002-08-02 at 10:43, Phil Dobbin wrote: >> That makes sense :-) I followed the example in the O'Reilly book (pp.25) >> and it didn't look right. This does, however. > >For future reference: IIRC the instruction in that book are for >installing the Pg module, which is a low level wrapper to libpq and NOT >a DBI module. > >If you're wondering what it has over DBI... just a more verbose and >closer to libpq syntax. Unlike some low level drivers I don't think this >one gives any finer control than you can get with the DBD:Pg one (it's a >wrapper for libpq as well). I'd personally suggest DBI for the >consistant interface across DBMSs. I was only questioning the syntax of setting the environment variable generally that the book sets out (pp.25). I _think_ Pg and DBD::Pg are the same thing, just different ways of saying things (i.e. Pg module would be DBD::Pg). I called it from CPAN after all ;-). In order to use DBI/DBD with postgres, it's the only way to do it as far as I can see (``There's more than one way to do it" anon ;-) O'Reilly's ``PostgreSQL" and ``Programming the Perl DBI" are both pretty vague on this (I have both). I'll also post to dbi-perl and see what gives (or what Tim Bunce sez...). Regards, Phil.
On Fri, 2002-08-02 at 18:45, phildobbin@pobox.com wrote: > I was only questioning the syntax of setting the environment variable > generally that the book sets out (pp.25). Those are very different env variables that are not at all related to DBD::Pg which does not come with the PostgreSQL distribution. > I _think_ Pg and DBD::Pg are the same thing, just different ways of > saying things (i.e. Pg module would be DBD::Pg). Nope. That's what I was saying. Pg is NOT DBD::Pg. The module that comes bundled with Postgres is Pg, a very low level wrapper. > I called it from CPAN after all ;-) http://search.cpan.org/doc/MERGL/pgsql_perl5-1.9.0/Pg.pm -- CPAN Pg http://search.cpan.org/doc/JBAKER/DBD-Pg-1.13/dbd-pg.pod -- CPAN DBD::Pg Very different modules. (Edmund Mergl originally wrote both, Jeffery Baker recently took over maintaining DBD::Pg) > In order to use DBI/DBD with postgres, it's the only way > to do it as far as I can see (``There's more than one way to do it" anon ;-) > > O'Reilly's ``PostgreSQL" and ``Programming the Perl DBI" are both pretty > vague on this (I have both). I'll also post to dbi-perl and see what > gives (or what Tim Bunce sez...). I fully agree. The PostgreSQL book only talks about the bundled module (Pg) and PL/Perl and both only to mention they exist. 'Programming the Perl DBI' just includes DBD::Pg's POD in the appendix, the installation instructions are actually in the README in the archive. Maybe it's time to add an interactive bit to the modules install (with a flag to deactivate it). This question crops up often and it makes CPAN installs hard for many people.
On 2/8/02 at 19:23, arguile@lucentstudios.com (Arguile) wrote: > On Fri, 2002-08-02 at 18:45, phildobbin@pobox.com wrote: [...] > > I _think_ Pg and DBD::Pg are the same thing, just different ways of > > saying things (i.e. Pg module would be DBD::Pg). > > Nope. That's what I was saying. Pg is NOT DBD::Pg. The module that > comes > bundled with Postgres is Pg, a very low level wrapper. > > > I called it from CPAN after all ;-) > > http://search.cpan.org/doc/MERGL/pgsql_perl5-1.9.0/Pg.pm -- CPAN Pg > http://search.cpan.org/doc/JBAKER/DBD-Pg-1.13/dbd-pg.pod -- CPAN > DBD::Pg > > Very different modules. > > (Edmund Mergl originally wrote both, Jeffery Baker recently took over > maintaining DBD::Pg) > > > In order to use DBI/DBD with postgres, it's the only way > > to do it as far as I can see (``There's more than one way to do it" > anon ;-) > > > > O'Reilly's ``PostgreSQL" and ``Programming the Perl DBI" are both > pretty > > vague on this (I have both). I'll also post to dbi-perl and see what > > gives (or what Tim Bunce sez...). > > I fully agree. The PostgreSQL book only talks about the bundled module > (Pg) and PL/Perl and both only to mention they exist. 'Programming the > Perl DBI' just includes DBD::Pg's POD in the appendix, the > installation > instructions are actually in the README in the archive. > > Maybe it's time to add an interactive bit to the modules install (with > a > flag to deactivate it). This question crops up often and it makes CPAN > installs hard for many people. Thanks a lot for the clear, concise explanation. I'm sorry to have kept banging on when clearly digging myself a hole :-) Your suggestion for making this more straightforward is a very good idea and would help a lot of people migrating to postgresand wanting to use DBI. Thanks for your patience and good advice. Best regards, Phil.