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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.