Skip to content

Commit b97f385

Browse files
authored
postgresql: Support string concat operator (#701)
1 parent fd3d7f9 commit b97f385

File tree

6 files changed

+120
-4
lines changed

6 files changed

+120
-4
lines changed

internal/compiler/resolve.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,19 @@ func resolveCatalogRefs(c *catalog.Catalog, rvs []*ast.RangeVar, args []paramRef
9898
})
9999

100100
if len(list.Items) == 0 {
101-
return nil, &sqlerr.Error{
102-
Code: "XXXXX",
103-
Message: "no column reference found",
104-
Location: n.Location,
101+
// TODO: Move this to database-specific engine package
102+
dataType := "any"
103+
if astutils.Join(n.Name, ".") == "||" {
104+
dataType = "string"
105105
}
106+
a = append(a, Parameter{
107+
Number: ref.ref.Number,
108+
Column: &Column{
109+
Name: parameterName(ref.ref.Number, ""),
110+
DataType: dataType,
111+
},
112+
})
113+
continue
106114
}
107115

108116
switch left := list.Items[0].(type) {

internal/endtoend/testdata/operator_string_concat/postgresql/go/db.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/operator_string_concat/postgresql/go/models.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/operator_string_concat/postgresql/go/query.sql.go

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE demo (txt text not null);
2+
3+
-- name: Test :one
4+
select * from Demo
5+
where txt ~~ '%' || sqlc.arg('val') || '%';
6+
7+
-- name: Test2 :one
8+
select * from Demo
9+
where txt like '%' || sqlc.arg('val') || '%';
10+
11+
-- name: Test3 :one
12+
select * from Demo
13+
where txt like concat('%', sqlc.arg('val'), '%');
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"engine": "postgresql",
7+
"name": "querytest",
8+
"schema": "query.sql",
9+
"queries": "query.sql"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)