Skip to content

Commit d24b495

Browse files
committed
Added more PostgreSQL functions
1 parent 9b74d0e commit d24b495

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2504
-6
lines changed

server/functions/abs.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2024 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 functions
16+
17+
import (
18+
"github.com/dolthub/doltgresql/utils"
19+
)
20+
21+
// abs represents the PostgreSQL function of the same name.
22+
var abs = Function{
23+
Name: "abs",
24+
Overloads: []interface{}{abs_int, abs_float, abs_numeric},
25+
}
26+
27+
// abs_int is one of the overloads of abs.
28+
func abs_int(num IntegerType) (IntegerType, error) {
29+
if num.IsNull {
30+
return IntegerType{IsNull: true}, nil
31+
}
32+
return IntegerType{Value: utils.Abs(num.Value)}, nil
33+
}
34+
35+
// abs_float is one of the overloads of abs.
36+
func abs_float(num FloatType) (FloatType, error) {
37+
if num.IsNull {
38+
return FloatType{IsNull: true}, nil
39+
}
40+
return FloatType{Value: utils.Abs(num.Value)}, nil
41+
}
42+
43+
// abs_numeric is one of the overloads of abs.
44+
func abs_numeric(num NumericType) (NumericType, error) {
45+
if num.IsNull {
46+
return NumericType{IsNull: true}, nil
47+
}
48+
return NumericType{Value: utils.Abs(num.Value)}, nil
49+
}

server/functions/acos.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// acos represents the PostgreSQL function of the same name.
20+
var acos = Function{
21+
Name: "acos",
22+
Overloads: []interface{}{acos_float},
23+
}
24+
25+
// acos_float is one of the overloads of acos.
26+
func acos_float(num FloatType) (FloatType, error) {
27+
if num.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: math.Acos(num.Value)}, nil
31+
}

server/functions/acosd.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// acosd represents the PostgreSQL function of the same name.
20+
var acosd = Function{
21+
Name: "acosd",
22+
Overloads: []interface{}{acosd_float},
23+
}
24+
25+
// acosd_float is one of the overloads of acosd.
26+
func acosd_float(num FloatType) (FloatType, error) {
27+
if num.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: toDegrees(math.Acos(num.Value))}, nil
31+
}

server/functions/acosh.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// acosh represents the PostgreSQL function of the same name.
20+
var acosh = Function{
21+
Name: "acosh",
22+
Overloads: []interface{}{acosh_float},
23+
}
24+
25+
// acosh_float is one of the overloads of acosh.
26+
func acosh_float(num FloatType) (FloatType, error) {
27+
if num.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: math.Acosh(num.Value)}, nil
31+
}

server/functions/ascii.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2024 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 functions
16+
17+
// ascii represents the PostgreSQL function of the same name.
18+
var ascii = Function{
19+
Name: "ascii",
20+
Overloads: []interface{}{ascii_string},
21+
}
22+
23+
// ascii_string is one of the overloads of ascii.
24+
func ascii_string(text StringType) (IntegerType, error) {
25+
if text.IsNull {
26+
return IntegerType{IsNull: true}, nil
27+
}
28+
if len(text.Value) == 0 {
29+
return IntegerType{Value: 0}, nil
30+
}
31+
runes := []rune(text.Value)
32+
return IntegerType{Value: int64(runes[0])}, nil
33+
}

server/functions/asin.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// asin represents the PostgreSQL function of the same name.
20+
var asin = Function{
21+
Name: "asin",
22+
Overloads: []interface{}{asin_float},
23+
}
24+
25+
// asin_float is one of the overloads of asin.
26+
func asin_float(num FloatType) (FloatType, error) {
27+
if num.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: math.Asin(num.Value)}, nil
31+
}

server/functions/asind.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// asind represents the PostgreSQL function of the same name.
20+
var asind = Function{
21+
Name: "asind",
22+
Overloads: []interface{}{asind_float},
23+
}
24+
25+
// asind_float is one of the overloads of asind.
26+
func asind_float(num FloatType) (FloatType, error) {
27+
if num.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: toDegrees(math.Asin(num.Value))}, nil
31+
}

server/functions/asinh.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// asinh represents the PostgreSQL function of the same name.
20+
var asinh = Function{
21+
Name: "asinh",
22+
Overloads: []interface{}{asinh_float},
23+
}
24+
25+
// asinh_float is one of the overloads of asinh.
26+
func asinh_float(num FloatType) (FloatType, error) {
27+
if num.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: math.Asinh(num.Value)}, nil
31+
}

server/functions/atan.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// atan represents the PostgreSQL function of the same name.
20+
var atan = Function{
21+
Name: "atan",
22+
Overloads: []interface{}{atan_float},
23+
}
24+
25+
// atan_float is one of the overloads of atan.
26+
func atan_float(num FloatType) (FloatType, error) {
27+
if num.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: math.Atan(num.Value)}, nil
31+
}

server/functions/atan2.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// atan2 represents the PostgreSQL function of the same name.
20+
var atan2 = Function{
21+
Name: "atan2",
22+
Overloads: []interface{}{atan2_float},
23+
}
24+
25+
// atan2_float is one of the overloads of atan2.
26+
func atan2_float(y FloatType, x FloatType) (FloatType, error) {
27+
if y.IsNull || x.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: math.Atan2(y.Value, x.Value)}, nil
31+
}

server/functions/atan2d.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 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 functions
16+
17+
import "math"
18+
19+
// atan2d represents the PostgreSQL function of the same name.
20+
var atan2d = Function{
21+
Name: "atan2d",
22+
Overloads: []interface{}{atan2d_float},
23+
}
24+
25+
// atan2d_float is one of the overloads of atan2d.
26+
func atan2d_float(y FloatType, x FloatType) (FloatType, error) {
27+
if y.IsNull || x.IsNull {
28+
return FloatType{IsNull: true}, nil
29+
}
30+
return FloatType{Value: toDegrees(math.Atan2(y.Value, x.Value))}, nil
31+
}

0 commit comments

Comments
 (0)