PostgreSQL database access

J

Justin C

I've a PostgreSQL database that I need to interact with using perl. I
need to be able to add records and amend records only. I'm trying to
find where to start. Searching CPAN for PostgreSQL returns a large list
of modules, I've been through a lot of pages and nothing stands out as
being the/a module that I need. Is there a good reference anywhere, in
simple terms (I've no experience *at all* with databases - but I do have
a book!), that'll tell me which module(s) I need?

Thank you for any help you are able to give.

Justin.
 
T

Tim Southerwood

Justin said:
I've a PostgreSQL database that I need to interact with using perl. I
need to be able to add records and amend records only. I'm trying to
find where to start. Searching CPAN for PostgreSQL returns a large list
of modules, I've been through a lot of pages and nothing stands out as
being the/a module that I need. Is there a good reference anywhere, in
simple terms (I've no experience *at all* with databases - but I do have
a book!), that'll tell me which module(s) I need?

Thank you for any help you are able to give.

Justin.

Hi

Fortunately, there is only one sane answer:

DBI as the interface module

and DBD::pg as the driver (there are drivers for most databases which makes
it such a dream).

HTH

Tim
 
P

Paul Lalli

I've a PostgreSQL database that I need to interact with using perl. I
need to be able to add records and amend records only. I'm trying to
find where to start.
http://dbi.perl.org
http://search.cpan.org/~timb/DBI-1.56/DBI.pm
http://search.cpan.org/~dbdpg/DBD-Pg-1.49/Pg.pm

Searching CPAN for PostgreSQL returns a large list
of modules, I've been through a lot of pages and nothing stands out as
being the/a module that I need. Is there a good reference anywhere, in
simple terms (I've no experience *at all* with databases - but I do have
a book!),

Wait, what? You have no experience with databases, but you're trying
to write a script to do database interactivity? You are putting the
cart before the horse. You need to learn about Databases and SQL
before you attempt to do any programming using that database. I
suggest you find a group that will point you towards resources for
learning about these topics, and then once you're comfortable using a
database natively, come back here and read those sites above to learn
how to use that database in a Perl script.

Paul Lalli
 
T

Tim Southerwood

Justin said:
I've a PostgreSQL database that I need to interact with using perl. I
need to be able to add records and amend records only. I'm trying to
find where to start. Searching CPAN for PostgreSQL returns a large list
of modules, I've been through a lot of pages and nothing stands out as
being the/a module that I need. Is there a good reference anywhere, in
simple terms (I've no experience *at all* with databases - but I do have
a book!), that'll tell me which module(s) I need?

Oh, for the "howto":

perldoc DBI

and look at the SYNOPSIS.

I think you mostly need:

$rv = $dbh->do($statement, \%attr, @bind_values);

(or perhaps prepare and execute, but do() will do for starters).

Hint - use bindvars, it will save infinite grief with quoting

perldoc DBD::pg will give you the magic for setting up a Postgresql DSN.

Another hint: setting RaiseError is a good idea - anything goes wrong and it
will blow up your code, even without explicit error checks, which is
usually a GOOD THING (TM) unless you really want to handle failures nicely.

HTH

Tim
 
K

Keith Keller

I've a PostgreSQL database that I need to interact with using perl. I
need to be able to add records and amend records only.

You've already gotten the Perl-relevant parts of your answer; I'll just
add that restricting access to add or update is a function of the db, so
you should read the PostgreSQL documention at their website for these
tasks.

--keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top