Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/compiler/query_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ func (comp *Compiler) buildQueryCatalog(c *catalog.Catalog, node ast.Node, embed
case *ast.DeleteStmt:
with = n.WithClause
case *ast.InsertStmt:
with = n.WithClause
if selectStmt, ok := n.SelectStmt.(*ast.SelectStmt); ok && selectStmt.WithClause != nil {
with = selectStmt.WithClause
} else {
with = n.WithClause
}
case *ast.UpdateStmt:
with = n.WithClause
case *ast.SelectStmt:
Expand Down
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/insert_cte_select/mysql/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions internal/endtoend/testdata/insert_cte_select/mysql/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions internal/endtoend/testdata/insert_cte_select/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions internal/endtoend/testdata/insert_cte_select/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- name: CreateAuthor :exec
insert into authors (id, name, bio)
with potential_authors as (
select id, name, bio
from dummy
)
select id, name, bio
from potential_authors;
11 changes: 11 additions & 0 deletions internal/endtoend/testdata/insert_cte_select/mysql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table authors (
id integer primary key,
name text not null,
bio text
);

create table dummy (
id integer primary key,
name text not null,
bio text
);
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/insert_cte_select/mysql/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"engine": "mysql",
"path": "go",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- name: CreateAuthor :exec
insert into authors (id, name, bio)
with potential_authors as (
select id, name, bio
from dummy
)
select id, name, bio
from potential_authors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table authors (
id integer primary key,
name text not null,
bio text
);

create table dummy (
id integer primary key,
name text not null,
bio text
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- name: CreateAuthor :exec
insert into authors (id, name, bio)
with potential_authors as (
select id, name, bio
from dummy
)
select id, name, bio
from potential_authors;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
create table authors (
id integer primary key,
name text not null,
bio text
);

create table dummy (
id integer primary key,
name text not null,
bio text
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading