1

When I execute a SQL command via libpq, it reports error message if there's some error something like this.

Error Domain=PQConnection Code=1 "ERROR:  syntax error at or near "fef"
LINE 1: fef
        ^

This is string message. I can parse the message - because it's very regular - to get line/column number, but that's unreliable. Is there any other API to get line/column numbers? Any regularized integer form would be nice.

eonil
  • 83,476
  • 81
  • 317
  • 516

1 Answers1

1

Use PQresultErrorField function with key PG_DIAG_STATEMENT_POSITION.

From manual

PG_DIAG_STATEMENT_POSITION A string containing a decimal integer indicating an error cursor position as an index into the original statement string. The first character has index 1, and positions are measured in characters not bytes.

eonil
  • 83,476
  • 81
  • 317
  • 516