Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Postgres default access methods in pg_am table #636

Merged
merged 3 commits into from
Aug 21, 2024
Merged
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
8 changes: 4 additions & 4 deletions server/functions/ascii.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (

// initAscii registers the functions to the catalog.
func initAscii() {
framework.RegisterFunction(ascii_varchar)
framework.RegisterFunction(ascii_text)
}

// ascii_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var ascii_varchar = framework.Function1{
// ascii_text represents the PostgreSQL function of the same name, taking the same parameters.
var ascii_text = framework.Function1{
Name: "ascii",
Return: pgtypes.Int32,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1Interface any) (any, error) {
val1 := val1Interface.(string)
Expand Down
10 changes: 5 additions & 5 deletions server/functions/bit_length.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import (

// initBitLength registers the functions to the catalog.
func initBitLength() {
framework.RegisterFunction(bit_length_varchar)
framework.RegisterFunction(bit_length_text)
}

// bit_length_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var bit_length_varchar = framework.Function1{
// bit_length_text represents the PostgreSQL function of the same name, taking the same parameters.
var bit_length_text = framework.Function1{
Name: "bit_length",
Return: pgtypes.Int32,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, t [2]pgtypes.DoltgresType, val1 any) (any, error) {
result, err := octet_length_varchar.Callable(ctx, t, val1)
result, err := octet_length_text.Callable(ctx, t, val1)
if err != nil {
return nil, err
}
Expand Down
30 changes: 23 additions & 7 deletions server/functions/btrim.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,36 @@ import (

// initBtrim registers the functions to the catalog.
func initBtrim() {
framework.RegisterFunction(btrim_varchar_varchar)
framework.RegisterFunction(btrim_text)
framework.RegisterFunction(btrim_text_text)
}

// btrim_varchar_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var btrim_varchar_varchar = framework.Function2{
// btrim_text represents the PostgreSQL function of the same name, taking the same parameters.
var btrim_text = framework.Function1{
Name: "btrim",
Return: pgtypes.VarChar,
Parameters: [2]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, t [2]pgtypes.DoltgresType, str any) (any, error) {
result, err := ltrim_text.Callable(ctx, t, str)
if err != nil {
return nil, err
}
return rtrim_text.Callable(ctx, t, result)
},
}

// btrim_text_text represents the PostgreSQL function of the same name, taking the same parameters.
var btrim_text_text = framework.Function2{
Name: "btrim",
Return: pgtypes.Text,
Parameters: [2]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, t [3]pgtypes.DoltgresType, str any, characters any) (any, error) {
result, err := ltrim_varchar_varchar.Callable(ctx, t, str, characters)
result, err := ltrim_text_text.Callable(ctx, t, str, characters)
if err != nil {
return nil, err
}
return rtrim_varchar_varchar.Callable(ctx, t, result, characters)
return rtrim_text_text.Callable(ctx, t, result, characters)
},
}
14 changes: 7 additions & 7 deletions server/functions/char_length.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import (

// initCharLength registers the functions to the catalog.
func initCharLength() {
framework.RegisterFunction(char_length_varchar)
framework.RegisterFunction(char_length_text)
// Register alias
character_length_varchar := char_length_varchar
character_length_varchar.Name = "character_length"
framework.RegisterFunction(character_length_varchar)
character_length_text := char_length_text
character_length_text.Name = "character_length"
framework.RegisterFunction(character_length_text)
}

// char_length_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var char_length_varchar = framework.Function1{
// char_length_text represents the PostgreSQL function of the same name, taking the same parameters.
var char_length_text = framework.Function1{
Name: "char_length",
Return: pgtypes.Int32,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
return int32(len([]rune(val1.(string)))), nil
Expand Down
2 changes: 1 addition & 1 deletion server/functions/chr.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func initChr() {
// chr_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var chr_int32 = framework.Function1{
Name: "chr",
Return: pgtypes.VarChar,
Return: pgtypes.Text,
Parameters: [1]pgtypes.DoltgresType{pgtypes.Int32},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1Interface any) (any, error) {
Expand Down
10 changes: 5 additions & 5 deletions server/functions/initcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (

// initInitcap registers the functions to the catalog.
func initInitcap() {
framework.RegisterFunction(initcap_varchar)
framework.RegisterFunction(initcap_text)
}

// initcap_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var initcap_varchar = framework.Function1{
// initcap_text represents the PostgreSQL function of the same name, taking the same parameters.
var initcap_text = framework.Function1{
Name: "initcap",
Return: pgtypes.VarChar,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
return cases.Title(language.English).String(val1.(string)), nil
Expand Down
10 changes: 5 additions & 5 deletions server/functions/left.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (

// initLeft registers the functions to the catalog.
func initLeft() {
framework.RegisterFunction(left_varchar_int32)
framework.RegisterFunction(left_text_int32)
}

// left_varchar_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var left_varchar_int32 = framework.Function2{
// left_text_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var left_text_int32 = framework.Function2{
Name: "left",
Return: pgtypes.VarChar,
Parameters: [2]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.Int32},
Return: pgtypes.Text,
Parameters: [2]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Int32},
Strict: true,
Callable: func(ctx *sql.Context, _ [3]pgtypes.DoltgresType, strInt any, nInt any) (any, error) {
str := strInt.(string)
Expand Down
8 changes: 4 additions & 4 deletions server/functions/length.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (

// initLength registers the functions to the catalog.
func initLength() {
framework.RegisterFunction(length_varchar)
framework.RegisterFunction(length_text)
}

// length_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var length_varchar = framework.Function1{
// length_text represents the PostgreSQL function of the same name, taking the same parameters.
var length_text = framework.Function1{
Name: "length",
Return: pgtypes.Int32,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
return int32(len([]rune(val1.(string)))), nil
Expand Down
10 changes: 5 additions & 5 deletions server/functions/lower.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (

// initLower registers the functions to the catalog.
func initLower() {
framework.RegisterFunction(lower_varchar)
framework.RegisterFunction(lower_text)
}

// lower_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var lower_varchar = framework.Function1{
// lower_text represents the PostgreSQL function of the same name, taking the same parameters.
var lower_text = framework.Function1{
Name: "lower",
Return: pgtypes.VarChar,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
//TODO: this doesn't respect collations
Expand Down
22 changes: 11 additions & 11 deletions server/functions/lpad.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ import (

// initLpad registers the functions to the catalog.
func initLpad() {
framework.RegisterFunction(lpad_varchar_int32)
framework.RegisterFunction(lpad_varchar_int32_varchar)
framework.RegisterFunction(lpad_text_int32)
framework.RegisterFunction(lpad_text_int32_text)
}

// lpad_varchar_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var lpad_varchar_int32 = framework.Function2{
// lpad_text_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var lpad_text_int32 = framework.Function2{
Name: "lpad",
Return: pgtypes.VarChar,
Parameters: [2]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.Int32},
Return: pgtypes.Text,
Parameters: [2]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Int32},
Strict: true,
Callable: func(ctx *sql.Context, _ [3]pgtypes.DoltgresType, val1 any, val2 any) (any, error) {
var unusedTypes [4]pgtypes.DoltgresType
return lpad_varchar_int32_varchar.Callable(ctx, unusedTypes, val1, val2, " ")
return lpad_text_int32_text.Callable(ctx, unusedTypes, val1, val2, " ")
},
}

// lpad_varchar_int32_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var lpad_varchar_int32_varchar = framework.Function3{
// lpad_text_int32_text represents the PostgreSQL function of the same name, taking the same parameters.
var lpad_text_int32_text = framework.Function3{
Name: "lpad",
Return: pgtypes.VarChar,
Parameters: [3]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.Int32, pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [3]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Int32, pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [4]pgtypes.DoltgresType, str any, length any, fill any) (any, error) {
if length.(int32) <= 0 {
Expand Down
22 changes: 11 additions & 11 deletions server/functions/ltrim.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ import (

// initLtrim registers the functions to the catalog.
func initLtrim() {
framework.RegisterFunction(ltrim_varchar)
framework.RegisterFunction(ltrim_varchar_varchar)
framework.RegisterFunction(ltrim_text)
framework.RegisterFunction(ltrim_text_text)
}

// ltrim_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var ltrim_varchar = framework.Function1{
// ltrim_text represents the PostgreSQL function of the same name, taking the same parameters.
var ltrim_text = framework.Function1{
Name: "ltrim",
Return: pgtypes.VarChar,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
var unusedTypes [3]pgtypes.DoltgresType
return ltrim_varchar_varchar.Callable(ctx, unusedTypes, val1, " ")
return ltrim_text_text.Callable(ctx, unusedTypes, val1, " ")
},
}

// ltrim_varchar_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var ltrim_varchar_varchar = framework.Function2{
// ltrim_text_text represents the PostgreSQL function of the same name, taking the same parameters.
var ltrim_text_text = framework.Function2{
Name: "ltrim",
Return: pgtypes.VarChar,
Parameters: [2]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [2]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [3]pgtypes.DoltgresType, str any, characters any) (any, error) {
runes := []rune(str.(string))
Expand Down
10 changes: 5 additions & 5 deletions server/functions/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (

// initMd5 registers the functions to the catalog.
func initMd5() {
framework.RegisterFunction(md5_varchar)
framework.RegisterFunction(md5_text)
}

// md5_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var md5_varchar = framework.Function1{
// md5_text represents the PostgreSQL function of the same name, taking the same parameters.
var md5_text = framework.Function1{
Name: "md5",
Return: pgtypes.VarChar,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
return fmt.Sprintf("%x", md5_package.Sum([]byte(val1.(string)))), nil
Expand Down
8 changes: 4 additions & 4 deletions server/functions/octet_length.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (

// initOctetLength registers the functions to the catalog.
func initOctetLength() {
framework.RegisterFunction(octet_length_varchar)
framework.RegisterFunction(octet_length_text)
}

// octet_length_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var octet_length_varchar = framework.Function1{
// octet_length_text represents the PostgreSQL function of the same name, taking the same parameters.
var octet_length_text = framework.Function1{
Name: "octet_length",
Return: pgtypes.Int32,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
return int32(len(val1.(string))), nil
Expand Down
10 changes: 5 additions & 5 deletions server/functions/repeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (

// initRepeat registers the functions to the catalog.
func initRepeat() {
framework.RegisterFunction(repeat_varchar_int32)
framework.RegisterFunction(repeat_text_int32)
}

// repeat_varchar_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var repeat_varchar_int32 = framework.Function2{
// repeat_text_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var repeat_text_int32 = framework.Function2{
Name: "repeat",
Return: pgtypes.VarChar,
Parameters: [2]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.Int32},
Return: pgtypes.Text,
Parameters: [2]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Int32},
Strict: true,
Callable: func(ctx *sql.Context, _ [3]pgtypes.DoltgresType, str any, num any) (any, error) {
return strings.Repeat(str.(string), int(num.(int32))), nil
Expand Down
10 changes: 5 additions & 5 deletions server/functions/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (

// initReplace registers the functions to the catalog.
func initReplace() {
framework.RegisterFunction(replace_varchar_varchar_varchar)
framework.RegisterFunction(replace_text_text_text)
}

// replace_varchar_varchar_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var replace_varchar_varchar_varchar = framework.Function3{
// replace_text_text_text represents the PostgreSQL function of the same name, taking the same parameters.
var replace_text_text_text = framework.Function3{
Name: "replace",
Return: pgtypes.VarChar,
Parameters: [3]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.VarChar, pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [3]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Text, pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [4]pgtypes.DoltgresType, str any, from any, to any) (any, error) {
if len(from.(string)) == 0 {
Expand Down
10 changes: 5 additions & 5 deletions server/functions/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (

// initReverse registers the functions to the catalog.
func initReverse() {
framework.RegisterFunction(reverse_varchar)
framework.RegisterFunction(reverse_text)
}

// reverse_varchar represents the PostgreSQL function of the same name, taking the same parameters.
var reverse_varchar = framework.Function1{
// reverse_text represents the PostgreSQL function of the same name, taking the same parameters.
var reverse_text = framework.Function1{
Name: "reverse",
Return: pgtypes.VarChar,
Parameters: [1]pgtypes.DoltgresType{pgtypes.VarChar},
Return: pgtypes.Text,
Parameters: [1]pgtypes.DoltgresType{pgtypes.Text},
Strict: true,
Callable: func(ctx *sql.Context, _ [2]pgtypes.DoltgresType, val1 any) (any, error) {
runes := []rune(val1.(string))
Expand Down
10 changes: 5 additions & 5 deletions server/functions/right.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (

// initRight registers the functions to the catalog.
func initRight() {
framework.RegisterFunction(right_varchar_int32)
framework.RegisterFunction(right_text_int32)
}

// right_varchar_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var right_varchar_int32 = framework.Function2{
// right_text_int32 represents the PostgreSQL function of the same name, taking the same parameters.
var right_text_int32 = framework.Function2{
Name: "right",
Return: pgtypes.VarChar,
Parameters: [2]pgtypes.DoltgresType{pgtypes.VarChar, pgtypes.Int32},
Return: pgtypes.Text,
Parameters: [2]pgtypes.DoltgresType{pgtypes.Text, pgtypes.Int32},
Strict: true,
Callable: func(ctx *sql.Context, _ [3]pgtypes.DoltgresType, strInt any, nInt any) (any, error) {
str := strInt.(string)
Expand Down
Loading
Loading