Skip to content

sqlc ignore paramter in LIKE #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yotamN opened this issue Feb 12, 2021 · 10 comments · Fixed by #1162
Closed

sqlc ignore paramter in LIKE #895

yotamN opened this issue Feb 12, 2021 · 10 comments · Fixed by #1162
Labels
question Further information is requested

Comments

@yotamN
Copy link

yotamN commented Feb 12, 2021

It seems that sqlc does not recognize a parameter inside a LIKE string, is there a special syntax for that or is it just not supported?

@kyleconroy
Copy link
Collaborator

I'm going to need more information before I reproduce your issue. Can you please answer the following questions:

  • What version of sqlc are you using?
  • What engine are you using (MySQL or PostgreSQL)?
  • What OS / arch are you on?

Can you also try to reproduce the issue in the sqlc playground?

@kyleconroy kyleconroy added the question Further information is requested label Feb 17, 2021
@konradreiche
Copy link

sqlc Playground

While this compiles fine:

-- name: SearchAuthor :many
SELECT * from authors WHERE name LIKE '%$1%';

It does not produce a parametrized method:

func (q *Queries) SearchAuthor(ctx context.Context) ([]Author, error)

@konradreiche
Copy link

konradreiche commented Feb 25, 2021

One workaround is to define it as:

-- name: SearchAuthor :many
SELECT * from authors WHERE name LIKE $1;

And specify the % as part of the string you are passing to the method.

@zono-dev
Copy link

Hi. I have had the same problem but it seems occur only when MySQL engine is used.

  • What version of sqlc are you using? -> v1.6.0
  • What engine are you using (MySQL or PostgreSQL)? -> MySQL
  • What OS / arch are you on? -> Linux(Alpine)

Playground: https://play.sqlc.dev/p/1f74d1fa215e49a51bedd8bab968826d5f772e1ffdd4c938ec78694823c033da

MySQL engine seems to ignore argument(s).

-- Example queries for sqlc
CREATE TABLE authors (
  id   SERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

-- name: SearchAuthor :many
SELECT * from authors WHERE name = $1;
// Code generated by sqlc. DO NOT EDIT.
// source: query.sql

package db

import (
	"context"
)

const searchAuthor = `-- name: SearchAuthor :many
SELECT id, name, bio from authors WHERE name = $1
`

func (q *Queries) SearchAuthor(ctx context.Context) ([]Author, error) {
	rows, err := q.db.QueryContext(ctx, searchAuthor)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Author
	for rows.Next() {
		var i Author
		if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

@fr3fou
Copy link

fr3fou commented Apr 18, 2021

Has this been fixed? The playground link still generates the wrong code.

@dytlan
Copy link

dytlan commented Apr 25, 2021

  • sqlc version : 1.7
  • Engine : MySQL

I have the same problem. LIKE is ignored

@amariucaitheodor
Copy link

  • sqlc version : 1.8
  • Engine : PostgreSQL

I have the same problem. LIKE is ignored

@a8uhnf
Copy link

a8uhnf commented Jun 30, 2021

Is there any possibility to add this feature for MySQL in near future?

@DuginKim
Copy link

sqlc version : 1.8
Engine : MySQL
LIKE is ignored

@dee-el
Copy link

dee-el commented Aug 9, 2021

this problem occured on me too, just when using MySQL

sqlc version : 1.8
Engine : MySQL
LIKE is ignored

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants