@@ -650,21 +650,32 @@ const (
650
650
// registered with pgtype.Map.RegisterDefaultPgType. Queries will be rejected that have arguments that are
651
651
// unregistered or ambiguous. e.g. A map[string]string may have the PostgreSQL type json or hstore. Modes that know
652
652
// the PostgreSQL type can use a map[string]string directly as an argument. This mode cannot.
653
+ //
654
+ // On rare occasions user defined types may behave differently when encoded in the text format instead of the binary
655
+ // format. For example, this could happen if a "type RomanNumeral int32" implements fmt.Stringer to format integers as
656
+ // Roman numerals (e.g. 7 is VII). The binary format would properly encode the integer 7 as the binary value for 7.
657
+ // But the text format would encode the integer 7 as the string "VII". As QueryExecModeExec uses the text format, it
658
+ // is possible that changing query mode from another mode to QueryExecModeExec could change the behavior of the query.
659
+ // This should not occur with types pgx supports directly and can be avoided by registering the types with
660
+ // pgtype.Map.RegisterDefaultPgType and implementing the appropriate type interfaces. In the cas of RomanNumeral, it
661
+ // should implement pgtype.Int64Valuer.
653
662
QueryExecModeExec
654
663
655
- // Use the simple protocol. Assume the PostgreSQL query parameter types based on the Go type of the arguments.
656
- // Queries are executed in a single round trip. Type mappings can be registered with
657
- // pgtype.Map.RegisterDefaultPgType. Queries will be rejected that have arguments that are unregistered or ambiguous.
658
- // e.g. A map[string]string may have the PostgreSQL type json or hstore. Modes that know the PostgreSQL type can use
659
- // a map[string]string directly as an argument. This mode cannot.
664
+ // Use the simple protocol. Assume the PostgreSQL query parameter types based on the Go type of the arguments. Queries
665
+ // are executed in a single round trip. Type mappings can be registered with pgtype.Map.RegisterDefaultPgType. Queries
666
+ // will be rejected that have arguments that are unregistered or ambiguous. e.g. A map[string]string may have the
667
+ // PostgreSQL type json or hstore. Modes that know the PostgreSQL type can use a map[string]string directly as an
668
+ // argument. This mode cannot.
660
669
//
661
- // QueryExecModeSimpleProtocol should have the user application visible behavior as QueryExecModeExec with minor
662
- // exceptions such as behavior when multiple result returning queries are erroneously sent in a single string.
670
+ // QueryExecModeSimpleProtocol should have the user application visible behavior as QueryExecModeExec. This includes
671
+ // the warning regarding differences in text format and binary format encoding with user defined types. There may be
672
+ // other minor exceptions such as behavior when multiple result returning queries are erroneously sent in a single
673
+ // string.
663
674
//
664
675
// QueryExecModeSimpleProtocol uses client side parameter interpolation. All values are quoted and escaped. Prefer
665
- // QueryExecModeExec over QueryExecModeSimpleProtocol whenever possible. In general QueryExecModeSimpleProtocol
666
- // should only be used if connecting to a proxy server, connection pool server, or non-PostgreSQL server that does
667
- // not support the extended protocol.
676
+ // QueryExecModeExec over QueryExecModeSimpleProtocol whenever possible. In general QueryExecModeSimpleProtocol should
677
+ // only be used if connecting to a proxy server, connection pool server, or non-PostgreSQL server that does not
678
+ // support the extended protocol.
668
679
QueryExecModeSimpleProtocol
669
680
)
670
681
0 commit comments