sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Escaping natural language w/ mysql?

Open JakeTrock opened this issue 1 year ago • 1 comments

Version

1.24.0

What happened?

I'm trying to do a little complicated SQL and it seems that I cannot properly escape the natural language to put in a question mark. I always only get 4 params when I should be getting 5. Does anyone know how I could escape the first so I can also have a natural language search param?

Relevant log output

No response

Database schema

CREATE TABLE Profile (
    id SERIAL PRIMARY KEY AUTO_INCREMENT UNIQUE,
    profileOwner VARCHAR(36) NOT NULL,
    name VARCHAR(512) NOT NULL,
    subHead VARCHAR(512) NOT NULL,
    body TEXT,
    locationLat FLOAT,
    locationLon FLOAT,
    createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updatedAt TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (profileOwner) REFERENCES User(id) ON DELETE CASCADE,
    FULLTEXT (name, body, subHead)
);

SQL queries

SELECT * FROM
    Profile
WHERE
    MATCH (subHead, body, name) 
    AGAINST (? IN NATURAL LANGUAGE MODE)
    AND locationLat BETWEEN ? AND ?
    AND locationLon BETWEEN ? AND ?;

Configuration

No response

Playground URL

https://play.sqlc.dev/p/69a6c4d31598994f1c63df14d1af302ab36de123d066552e2463b79653580d50

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

JakeTrock avatar Dec 31 '23 05:12 JakeTrock

@kyleconroy Sorry for pinging. But any updates on this? As of SQLC v1.29.0, the issue still exists.

haashemi avatar Apr 25 '25 22:04 haashemi

Fixed in https://github.com/sqlc-dev/sqlc/pull/4070

kyleconroy avatar Aug 24 '25 16:08 kyleconroy