Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Postgres query with LIKE #2037

Unanswered
Tomelin asked this question in Issue Triage
Discussion options

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ドル;
You must be logged in to vote

Replies: 1 comment

Comment options

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, '%')
 );
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /