{"record":{"id":"8b927dc60161bc71","repo":"jackc/pgx","slug":"escapestring-must-be-run-with-standard-conforming","errorCode":null,"errorMessage":"EscapeString must be run with standard_conforming_strings=on","messagePattern":"EscapeString must be run with standard_conforming_strings=on","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgconn/pgconn.go","lineNumber":2069,"sourceCode":"\tif err != nil {\n\t\tpgConn.contextWatcher.Unwatch()\n\t\tmultiResult.err = normalizeTimeoutError(multiResult.ctx, err)\n\t\tmultiResult.closed = true\n\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 {","sourceCodeStart":2051,"sourceCodeEnd":2087,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgconn/pgconn.go#L2051-L2087","documentation":"EscapeString guard: the connection's standard_conforming_strings server parameter is not 'on'. EscapeString's escaping algorithm is only correct when backslashes are not literal escape characters in string literals, so it refuses to run rather than produce unsafe SQL.","triggerScenarios":"Thrown at pgconn/pgconn.go:2069 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set standard_conforming_strings=on in postgresql.conf (the default since PostgreSQL 9.1)","Prefer parameterized queries or the pgtype text codec over manual string escaping"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}