#2573·mysql

Unable to use the question mark (?) character inside a string.

Author: 8483Created Sep 28, 2025Updated Aug 26, 2026

It gets treated as a variable placeholder and the ? is replaced with a passed in value.

sql
select concat(dt.url, '/', d.posId, '?posTransactionId=', d.id) url

The ? should have some escape mechanism like \? or something.

How can this be achieved?


EDIT:

Made it work like this, by passing the ? as a parameter, which doesn't feel good.

javascript
let sql = `
    set @tenantId = ?;
    set @questionMarkCharacter = ?;

    select 
        tenantId, 
        d.id, 
        concat(dt.name, ' - ', d.uid) name,
        concat(dt.url, '/', d.posId, @questionMarkCharacter, 'posTransactionId=', d.id) url
    from retail_posTransaction d
        left join system_documentType dt on dt.id = d.documentTypeId
    where tenantId = @tenantId
    ;
`

let result = await pool.query(query, [tenantId, "?"]);