1

How do I convert the following SQL query to GORM?

SELECT * FROM files WHERE tsv @@ plainto_tsquery('lexeme word');

Or equivalently:

SELECT * FROM files, plainto_tsquery('lexeme word') q WHERE tsv @@ q;

I can use .Exec():

err := d.Connection.DB.Exec("SELECT * FROM scenes WHERE tsv @@ plainto_tsquery(?);",text).Error
if err != nil {
    return nil, err
}

This query doesn't allow me to get an array of data and work with it. Unfortunately, I could not find a solution using the GORM documentation.

1 Answer 1

1

Use .Raw() for raw SQL query

db.Raw("SELECT id, name, age FROM users WHERE name = ?", 3).Scan(&result)

Official doc for about raw SQL query

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.