xiaobaicai66695 opened a new issue, #1145:
URL: https://github.com/apache/incubator-seata-go/issues/1145

   ### Description
   
   When PostgreSQL AT mode builds before-image SQL for `UPDATE` or `DELETE`, 
string literals that contain PostgreSQL-style placeholder text can be restored 
incorrectly and then misclassified as bind placeholders.
   
   For example:
   
   ```sql
   delete from t_user where id = $1 and note = '$2'
   ```
   
   The original SQL has only one bind argument. `$1` is a PostgreSQL bind 
placeholder, while `'$2'` is a string literal.
   
   During before-image SQL generation, Seata Go parses the SQL into an AST and 
restores a `SELECT ... FOR UPDATE` statement. The AST can distinguish the bind 
placeholder from the string literal, but the current restore/normalization path 
may turn the literal into:
   
   ```sql
   note=_UTF8MB4$2
   ```
   
   After that, `CompactPostgreSQLPlaceholders` scans the restored SQL text and 
treats every `$<digits>` sequence as a placeholder. As a result, the `$2` that 
originally belonged to the string literal is treated as the second bind 
argument, which can return:
   
   ```text
   postgres placeholder index 2 out of range
   ```
   
   or compact the wrong argument when enough arguments exist.
   
   ### Expected behavior
   
   The generated PostgreSQL before-image SQL should keep string literal 
boundaries and only compact placeholders that appear in SQL code, for example:
   
   ```sql
   SELECT * FROM t_user WHERE id=$1 AND note='$2' FOR UPDATE
   ```
   
   with arguments:
   
   ```text
   [100]
   ```
   
   ### Affected path
   
   - PostgreSQL AT `DELETE` before-image SQL generation
   - PostgreSQL AT `UPDATE` before-image SQL generation
   - PostgreSQL placeholder compaction after SQL restore
   
   ### Suggested fix
   
   - Restore PostgreSQL before-image SQL with string quotes preserved.
   - Normalize MySQL charset introducers emitted by the parser for PostgreSQL 
string literals, e.g. `_UTF8MB4'...'` -> `'...'`.
   - Make PostgreSQL placeholder compaction skip quoted strings, quoted 
identifiers, comments, and dollar-quoted strings.
   
   I am working on a patch for this issue. Please assign this issue to me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to