{"id":"cef70cfbcc703788","repo":"jackc/pgx","slug":"escapestring-must-be-run-with-client-encoding-utf8","errorCode":null,"errorMessage":"EscapeString must be run with client_encoding=UTF8","messagePattern":"EscapeString must be run with client_encoding=UTF8","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/pgconn.go","lineNumber":2073,"sourceCode":"\t\tpgConn.asyncClose()\n\t\treturn multiResult\n\t}\n\n\treturn multiResult\n}\n\n// EscapeString escapes a string such that it can safely be interpolated into a SQL command string. It does not include\n// the surrounding single quotes.\n//\n// The current implementation requires that standard_conforming_strings=on and client_encoding=\"UTF8\". If these\n// conditions are not met an error will be returned. It is possible these restrictions will be lifted in the future.\nfunc (pgConn *PgConn) EscapeString(s string) (string, error) {\n\tif pgConn.ParameterStatus(\"standard_conforming_strings\") != \"on\" {\n\t\treturn \"\", errors.New(\"EscapeString must be run with standard_conforming_strings=on\")\n\t}\n\n\tif pgConn.ParameterStatus(\"client_encoding\") != \"UTF8\" {\n\t\treturn \"\", errors.New(\"EscapeString must be run with client_encoding=UTF8\")\n\t}\n\n\treturn strings.ReplaceAll(s, \"'\", \"''\"), nil\n}\n\n// CheckConn checks the underlying connection without writing any bytes. This is currently implemented by doing a read\n// with a very short deadline. This can be useful because a TCP connection can be broken such that a write will appear\n// to succeed even though it will never actually reach the server. Reading immediately before a write will detect this\n// condition. If this is done immediately before sending a query it reduces the chances a query will be sent that fails\n// without the client knowing whether the server received it or not.\n//\n// Deprecated: CheckConn is deprecated in favor of Ping. CheckConn cannot detect all types of broken connections where\n// the write would still appear to succeed. Prefer Ping unless on a high latency connection.\nfunc (pgConn *PgConn) CheckConn() error {\n\tctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)\n\tdefer cancel()\n\n\t_, err := pgConn.ReceiveMessage(ctx)","sourceCodeStart":2055,"sourceCodeEnd":2091,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/pgconn.go#L2055-L2091","documentation":"Error \"EscapeString must be run with client_encoding=UTF8\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgconn/pgconn.go:2073 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}