Is your feature request related to a problem? Please describe.
Hello, I am using pgx with a connection string which includes target_session_attrs=read-write. The built in callback correctly rejects connections to read only replicas:
|
// ValidateConnectTargetSessionAttrsReadWrite is a ValidateConnectFunc that implements libpq compatible |
|
// target_session_attrs=read-write. |
|
func ValidateConnectTargetSessionAttrsReadWrite(ctx context.Context, pgConn *PgConn) error { |
|
result, err := pgConn.Exec(ctx, "show transaction_read_only").ReadAll() |
|
if err != nil { |
|
return err |
|
} |
|
|
|
if string(result[0].Rows[0][0]) == "on" { |
|
return errors.New("read only connection") |
|
} |
|
|
|
return nil |
|
} |
However, I cannot use errors.Is with this error, and have to assert the error text.
Describe the solution you'd like
I would like for there to be dedicated errors such that I can do errors.Is(err, package.ErrConnectionReadOnly) in my transaction retry logic.
Describe alternatives you've considered
The error can either live in pgconn, or somewhere else. I am not sure if it should be a new set of errors or we should reuse existing errors in order to reduce duplication - any feedback is open.
Additional context
I can implement this change, but please let me know your thoughts on which errors we should use.
Is your feature request related to a problem? Please describe.
Hello, I am using
pgxwith a connection string which includestarget_session_attrs=read-write. The built in callback correctly rejects connections to read only replicas:pgx/pgconn/config.go
Lines 1070 to 1083 in b56d88f
However, I cannot use
errors.Iswith this error, and have to assert the error text.Describe the solution you'd like
I would like for there to be dedicated errors such that I can do
errors.Is(err, package.ErrConnectionReadOnly)in my transaction retry logic.Describe alternatives you've considered
The error can either live in
pgconn, or somewhere else. I am not sure if it should be a new set of errors or we should reuse existing errors in order to reduce duplication - any feedback is open.Additional context
I can implement this change, but please let me know your thoughts on which errors we should use.