I want to connect to postgresql from perl file and get results

Asked 1 years ago, Updated 1 years ago, 93 views

I'm using the perl file pg (is it like including?) and doing pg::connectdb, but I'd like to check the return value of SQL.

# begin.

$conn=Pg::connectdb("host=$hostport=$portdbname=$dbname user=$user");
$result=$conn->exec("lock table table_name in access exclusive mode nowait;");

# commit or rollback.

In , I think $result will contain data, but if the query results are OK, $result->resultStatus; will contain a value, but I don't understand where to judge the sql error in the first place.

Where is the correct way to look?

postgresql perl

2022-09-30 19:08

1 Answers

I think the question is more about libpg than Perl, so I suggest you read libpg documents in addition to perldoc already mentioned.If Perldoc's Japanese translation is good, you can also find here.

Where is the correct way to look?

The query execution results are determined by a value of $result->resultStatus.
The value can be one of the following constants:

  • PGRES_EMPTY_QUERY
  • PGRES_COMMAND_OK
  • PGRES_TUPLES_OK
  • PGRES_COPY_OUT
  • PGRES_COPY_IN
  • PGRES_BAD_RESPONSE
  • PGRES_NONFATAL_ERROR
  • PGRES_FATAL_ERROR

The meaning of these constants is found in libpg's document.


2022-09-30 19:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.