Skip to content

Commit e585dec

Browse files
authored
Merge pull request #2227 from dolthub/daylon/issue-2206
Fixed issue 2206
2 parents d0c6209 + d616934 commit e585dec

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

postgres/parser/parser/sql.y

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9460,6 +9460,10 @@ index_elem:
94609460
{
94619461
$$.val = tree.IndexElem{Expr: $2.expr(), Collation: $4.unresolvedObjectName().UnquotedString(), OpClass: $5.opClass(), Direction: $6.dir(), NullsOrder: $7.nullsOrder()}
94629462
}
9463+
| func_expr opt_collate opt_opclass opt_asc_desc opt_nulls_order
9464+
{
9465+
$$.val = tree.IndexElem{Expr: $1.expr(), Collation: $2.unresolvedObjectName().UnquotedString(), OpClass: $3.opClass(), Direction: $4.dir(), NullsOrder: $5.nullsOrder()}
9466+
}
94639467

94649468
opt_opclass:
94659469
/* EMPTY */

testing/go/index_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,5 +1378,26 @@ func TestBasicIndexing(t *testing.T) {
13781378
},
13791379
},
13801380
},
1381+
{ // https://github.com/dolthub/doltgresql/issues/2206
1382+
Name: "Index attributes",
1383+
Skip: true, // We were getting a syntax error previously, which is fixed, however we don't yet support expression index attributes
1384+
SetUpScript: []string{
1385+
`CREATE TABLE IF NOT EXISTS items (id SERIAL PRIMARY KEY, title VARCHAR(100) NOT NULL, metadata JSON, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);`,
1386+
},
1387+
Assertions: []ScriptTestAssertion{
1388+
{
1389+
Query: "CREATE UNIQUE INDEX IF NOT EXISTS idx_items_title_lower ON items(lower(title));",
1390+
Expected: []sql.Row{},
1391+
},
1392+
{
1393+
Query: "INSERT INTO items (title, metadata, updated_at) VALUES ('ABC', '{}', '2026-10-10 01:02:03');",
1394+
Expected: []sql.Row{},
1395+
},
1396+
{
1397+
Query: "INSERT INTO items (title, metadata, updated_at) VALUES ('abc', '{}', '2026-11-12 03:04:05');",
1398+
ExpectedErr: "duplicate key value violates unique constraint",
1399+
},
1400+
},
1401+
},
13811402
})
13821403
}

0 commit comments

Comments
 (0)