Closed
Description
sqlc.yaml
version: "1"
packages:
- name: main
path: .
schema: schema.sql
queries: query.sql
engine: postgresql
emit_json_tags: true
emit_prepared_queries: false
emit_interface: true
emit_exact_table_names: false
emit_empty_slices: false
schema.sql
create table graph
(
id serial not null primary key,
data int not null
);
create unique index graph_id_uindex
on graph (id);
--
create table graph_link
(
g_id int not null
constraint graph_link_graph_id_fk
references graph (id),
import_g int not null
constraint graph_link_graph_id_fk_2
references graph (id)
);
create unique index graph_link_g_id_import_g_uindex
on graph_link (g_id, import_g);
query.sql
-- name: GetGraphDeps :many
WITH RECURSIVE search_graph(id, import_id, data, depth, path, cycle) AS (
SELECT gl.g_id id, gl.import_g import_id, g.data, 1 as depth,
ARRAY[gl.g_id] as path, false as cycle
FROM graph_link gl
JOIN graph g on g.id = gl.g_id
UNION ALL
SELECT gl.g_id id, gl.import_g import_id, g.data, search_graph.depth + 1 as depth,
search_graph.path || gl.import_g as path, gl.g_id = ANY(search_graph.path) as cycle
FROM (graph_link gl JOIN graph g on g.id = gl.g_id),
search_graph
WHERE gl.g_id = search_graph.import_id AND NOT search_graph.cycle
)
SELECT DISTINCT search_graph.id, search_graph.depth, search_graph.data FROM search_graph;
sqlc generate
gives me
query.sql:11:17: column "id" does not exist