Merge pull request #511 from Andrei-hub11/fix/digit-schema-quote

fix: quote identifiers starting with numbers
This commit is contained in:
go-jet 2025-07-22 19:07:53 +02:00 committed by GitHub
commit d375d06267
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View file

@ -4,15 +4,16 @@ import (
"bytes"
"database/sql/driver"
"fmt"
"github.com/go-jet/jet/v2/internal/3rdparty/pq"
"github.com/go-jet/jet/v2/internal/utils/is"
"github.com/google/uuid"
"reflect"
"sort"
"strconv"
"strings"
"time"
"unicode"
"github.com/go-jet/jet/v2/internal/3rdparty/pq"
"github.com/go-jet/jet/v2/internal/utils/is"
"github.com/google/uuid"
)
// SQLBuilder generates output SQL
@ -309,8 +310,8 @@ func shouldQuoteIdentifier(identifier string) bool {
}
// check if contains non ascii characters
for _, c := range identifier {
if unicode.IsNumber(c) || c == '_' {
for i, c := range identifier {
if (unicode.IsNumber(c) && i > 0) || c == '_' {
continue
}
if c > unicode.MaxASCII || !unicode.IsLetter(c) || unicode.IsUpper(c) {

View file

@ -1,10 +1,11 @@
package jet
import (
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"testing"
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
)
func TestArgToString(t *testing.T) {
@ -58,4 +59,5 @@ func TestShouldQuote(t *testing.T) {
require.Equal(t, shouldQuoteIdentifier("abc_123"), false)
require.Equal(t, shouldQuoteIdentifier("Abc_123"), true)
require.Equal(t, shouldQuoteIdentifier("DŽƜĐǶ"), true)
require.Equal(t, shouldQuoteIdentifier("1test"), true)
}