Skip to content

Can't generate join query, no error when run sqlc #836

Closed
@quagmt

Description

@quagmt

Hi, so this is my schema:

create table comics (
"id" serial UNIQUE,
"page" VARCHAR(64) not null,
"name" VARCHAR(128)not null,
"url" VARCHAR(256) not null unique,
"img_url" VARCHAR(128) not null,
"cloud_img_url" VARCHAR(256) not null,
"latest_chap" VARCHAR(128) not null,
"chap_url" VARCHAR(128) not null,
PRIMARY KEY (id, url, img_url)
);
create table users (
"id" serial UNIQUE,
"name" VARCHAR(64) not null,
"psid" VARCHAR(64) not null UNIQUE,
"appid" VARCHAR(64) not null UNIQUE,
"profile_pic" VARCHAR(256) not null,
PRIMARY KEY (psid, appid)
);
create table subscribers (
"id" serial,
"user_psid" VARCHAR(64) references users(psid) not null,
"comic_id" INT references comics(id) not null,
"created_at" timestamptz NOT NULL DEFAULT (now())
);

Basicly comics and users table has many-to-many relationship, which is in subscribers table. I want to get all comics subscribed by an user using this join query:

--name GetSubscribedComic :one
SELECT comics.id, comics.name
FROM comics
LEFT JOIN subscribers ON comics.id = subscribers.comic_id
WHERE subscribers.user_psid=$1 AND subscribers.comic_id=$2;

But something maybe wrong with sqlc, it generated sql.go file but doesn't have this query in it. Can you please check it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions