{"record":{"id":"d361e3dd0c5bc5b5","repo":"jackc/pgx","slug":"invalid-tsvector-format-lexeme-must-start-with-a","errorCode":null,"errorMessage":"invalid tsvector format: lexeme must start with a single quote","messagePattern":"invalid tsvector format: lexeme must start with a single quote","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/tsvector.go","lineNumber":366,"sourceCode":"\tif p.pos >= len(p.str) {\n\t\treturn 0, true\n\t}\n\tb := p.str[p.pos]\n\tp.pos++\n\treturn b, false\n}\n\nfunc (p *tsvectorParser) consumeSpaces() {\n\tfor !p.atEnd() && p.peek() == ' ' {\n\t\tp.consume()\n\t}\n}\n\n// consumeLexeme consumes a single-quoted lexeme, handling single quotes and backslash escapes.\nfunc (p *tsvectorParser) consumeLexeme() (string, error) {\n\tch, end := p.consume()\n\tif end || ch != '\\'' {\n\t\treturn \"\", fmt.Errorf(\"invalid tsvector format: lexeme must start with a single quote\")\n\t}\n\n\tvar buf strings.Builder\n\tfor {\n\t\tch, end := p.consume()\n\t\tif end {\n\t\t\treturn \"\", fmt.Errorf(\"invalid tsvector format: unterminated quoted lexeme\")\n\t\t}\n\n\t\tswitch ch {\n\t\tcase '\\'':\n\t\t\t// Escaped quote ('') — write a literal single quote\n\t\t\tif !p.atEnd() && p.peek() == '\\'' {\n\t\t\t\tp.consume()\n\t\t\t\tbuf.WriteByte('\\'')\n\t\t\t} else {\n\t\t\t\t// Closing quote — lexeme is complete\n\t\t\t\treturn buf.String(), nil","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/tsvector.go#L348-L384","documentation":"Text tsvector parser guard in consumeLexeme: a quoted lexeme must begin with an opening single quote, but the first consumed character was something else (or input ended). Applies when parsing lexemes that require quoting (spaces, quotes, special characters).","triggerScenarios":"Thrown at pgtype/tsvector.go:366 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Quote lexemes containing special characters: 'won''t' style with escaped quotes","Fix hand-built tsvector strings to follow PostgreSQL's text format","Let PostgreSQL produce the tsvector (to_tsvector) instead of constructing text manually"],"exampleFix":null,"handlingStrategy":"validation","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"}