Skip to content

Commit 2b7490f

Browse files
committed
Add UTF8 identifier support
1 parent 6c1032a commit 2b7490f

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

core/identifiers.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2026 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package core
16+
17+
// IsValidPostgresIdentifier returns true according to Postgres quoted identifier rules.
18+
// Quoted identifiers can contain any character except the null character (code zero),
19+
// including supplementary Unicode (emoji, code points above U+FFFF) unlike MySQL.
20+
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html
21+
func IsValidPostgresIdentifier(name string) bool {
22+
if len(name) == 0 {
23+
return false
24+
}
25+
for _, c := range name {
26+
if c == 0x0000 {
27+
return false
28+
}
29+
}
30+
return true
31+
}

server/tables/init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
package tables
1616

1717
import (
18+
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
1819
"github.com/dolthub/dolt/go/libraries/doltcore/sqle"
1920
"github.com/dolthub/go-mysql-server/sql"
21+
22+
"github.com/dolthub/doltgresql/core"
2023
)
2124

2225
// Init handles initialization of all Postgres-specific and Doltgres-specific tables.
@@ -27,4 +30,5 @@ func Init() {
2730
}
2831
return db, nil
2932
}
33+
doltdb.IsValidIdentifier = core.IsValidPostgresIdentifier
3034
}

testing/go/create_table_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ import (
2323

2424
func TestCreateTable(t *testing.T) {
2525
RunScripts(t, []ScriptTest{
26+
{
27+
// https://github.com/dolthub/doltgresql/issues/2580
28+
Name: "create table with UTF8 identifiers",
29+
Assertions: []ScriptTestAssertion{
30+
{
31+
Query: `CREATE TABLE foo😏(data🍆 TEXT);`,
32+
Expected: []sql.Row{},
33+
},
34+
{
35+
Query: `CREATE INDEX idx🍤 ON foo😏(data🍆);`,
36+
Expected: []sql.Row{},
37+
},
38+
{
39+
Query: `Insert into foo😏 (data🍆) VALUES ('foo');`,
40+
Expected: []sql.Row{},
41+
},
42+
{
43+
Query: `SELECT data🍆 FROM foo😏;`,
44+
Expected: []sql.Row{{"foo"}},
45+
},
46+
},
47+
},
2648
{
2749
Name: "create table with primary key",
2850
Assertions: []ScriptTestAssertion{

0 commit comments

Comments
 (0)