#!C:/strawberry/perl/bin/perl.exe use strict; use warnings; use DBI; use DBD::Pg; my $pwd ="MyPwd"; # my $dbh = DBI->connect('dbi:Pg:dbname=my_geo_table;host=dbhost', 'user', $pwd, { PrintError => 0, HandleError => \&handle_error, } ) or handle_error(DBI->errstr); my $some_text ="hello World"; my $LongDEC = "017.12.270"; my $LatDEC = "44.82115"; my $post_id = 123; my $cmd = "insert into latlong (post_id,some_text,geom) VALUES (" . $dbh->quote($post_id) . "," . $dbh->quote($some_text) . ", ST_GeomFromText('POINT($LongDEC $LatDEC)', 4326) )"; my $query_handle = $dbh->prepare($cmd); $query_handle->execute(); my $lastID = $dbh->last_insert_id(undef,undef,"latlong",undef); if(defined(DBI->errstr)) { ## not getting here my $ErrMsg .= "Error: " . handle_error(DBI->errstr); print $ErrMsg . "\n"; } else { print "Finished with $post_id lastid =[$lastID]\n"; } sub handle_error { my $message = shift; return ("### The Error message from DB is '$message' ###\n"); } ## These subs are for trapping warnings local $SIG{__WARN__} = sub { my $message = shift; print "warning $message\n"; # not getting here logger('warning', $message); }; sub logger { my ($level, $msg) = @_; if (open my $out, '>>', $dir . "\\log.txt") { chomp $msg; print $out "$level - $msg\n"; } } #### print out to cmd WARNING: OGC WKT expected, EWKT provided - use GeomFromEWKT() for this Finished with 123 lastid =[567] 1 records processed 0 error-ed