• Tom Lane's avatar
    SQL commands in pgbench scripts are now ended by semicolons, not newlines. · 68ab8e8b
    Tom Lane authored
    To allow multiline SQL commands in scripts, adopt the same rules psql uses
    to decide what is the end of a SQL command, to wit, an unquoted semicolon
    not encased in parentheses.  Do this by importing the same flex lexer that
    psql uses, since coping with stuff like dollar-quoted literals is hard to
    get right without going the full nine yards.
    
    This makes use of the infrastructure added in commit 0ea9efbe to
    support independently-written flex lexers scanning the same PsqlScanState
    input-buffer data structure.  Since that infrastructure isn't very
    friendly to ad-hoc parsing code such as strtok(), improve exprscan.l
    so that it can parse either whitespace-separated words or expression
    tokens, on demand, and rewrite pgbench.c's backslash-command parsing
    code to always use the lexer to fetch tokens.
    
    It's still the case that pgbench backslash commands extend to the end
    of the line, no more and no less.  That could be changed in a fairly
    localized way now, and there was some interest in doing so, but it
    seems like material for a separate patch.
    
    In passing, make some marginal cleanups in syntax error reporting,
    const-ify a few data structures that could use it, and run some of
    this code through pgindent.
    
    I can't tell whether the MSVC build scripts need to be taught explicitly
    about the changes here or not, but the buildfarm will soon tell us.
    
    Kyotaro Horiguchi and Tom Lane
    68ab8e8b
exprscan.l 8.39 KB