Closed mhkarimi1383 closed 1 year ago
@mhkarimi1383 Can you describe a bit more what your use case is?
Technically some of this information is available (see the complete error object in libpg_query), but today we don't use it in the Go library:
https://github.com/pganalyze/pg_query_go/blob/main/parser/parser.go#L82
We could expand that error handling, but it would require a bit of an API redesign, so it would be good to understand a bit better what you're trying to do. Note that some of this information (e.g. SchemaName, etc) is not available because pg_query works with the raw parse tree (i.e. without parse analysis that maps to actual database objects).
I'm working on a project and I want to return that error to user directly without sending that query to postgres so I need full structured error
@mhkarimi1383 Makes sense - just saw your pg_pro project on your GitHub profile - that looks like a cool project!
This actually was pretty straightforward to add, I just did a quick try at this in #76
Do you want to test that PR and see whether that solves your use case?
As mentioned this is not all the possible error fields, but for basic errors like "this query fails to parse" it should match what Postgres itself would return to a client, except for the SQL error code, which is generated outside of the part of Postgres we currently work with -- I believe that's represented as Code
in your struct above (you could just hard code that to the SQL error code matching parser errors, I believe that might be always the same).
Thanks I will test as I get into my system
@lfittl Worked thanks, but I was not able to map Funcname
to one of those fields in that struct
, also I mapped Context
field to Details
@lfittl any updates?
Hi I need to translate parse errors to pgproto error responses with the struct below
but I was not able to find a way to query parse errors (like invalid queries, etc.)