-
Notifications
You must be signed in to change notification settings - Fork 947
Postgres query with LIKE #2037
Unanswered
Tomelin
asked this question in
Issue Triage
Postgres query with LIKE
#2037
-
Hi all,
I have the Golang+Postgres+SQLC e I need create the query with LIKE but the postgres syntaxe is not accepet in SQLC queries. I try this format:
-- name: FindOrganization :many
SELECT * FROM organization
WHERE deleted_at IS NULL and name LIKE % 1ドル % or description=2ドル or tag LIKE 3ドル;
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
1- Install the following Postgres extensions
create extension if not exists btree_gin;
create extension if not exists pg_trgm;
2- Modify organization table by adding these 2 indexes
create index if not exists ix_organization_name_trgm on organization using gin (name gin_trgm_ops);
create index if not exists ix_organization_tag_trgm on organization using gin (tag gin_trgm_ops);
3- Rewrite the query as below
-- name: FindOrganization :many
select *
from organization
where deleted_at is null and
(
name ilike concat('%', @name_match::text, '%') or
description=2ドル or
tag ilike concat('%', @tag_match::text, '%')
);
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment