• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torand / FasterSQL / 15346133148

30 May 2025 11:50AM UTC coverage: 70.397% (+0.1%) from 70.298%
15346133148

push

github

torand
chore: test javadoc publish

235 of 420 branches covered (55.95%)

Branch coverage included in aggregate %.

1237 of 1671 relevant lines covered (74.03%)

3.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/src/main/java/io/github/torand/fastersql/dialect/PostgreSqlDialect.java
1
/*
2
 * Copyright (c) 2024-2025 Tore Eide Andersen
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.torand.fastersql.dialect;
17

18
import java.util.EnumSet;
19
import java.util.List;
20
import java.util.Optional;
21

22
import static io.github.torand.fastersql.dialect.Capability.CONCAT_OPERATOR;
23
import static io.github.torand.fastersql.dialect.Capability.CURRENT_TIME;
24
import static io.github.torand.fastersql.dialect.Capability.LIMIT_OFFSET;
25
import static io.github.torand.fastersql.dialect.Capability.MODULO_OPERATOR;
26
import static io.github.torand.fastersql.dialect.Capability.NULL_ORDERING;
27
import static io.github.torand.fastersql.dialect.Capability.SELECT_FOR_UPDATE;
28
import static io.github.torand.fastersql.dialect.Capability.TRUNCATE_TABLE;
29
import static io.github.torand.fastersql.util.lang.StringHelper.generate;
30

31
/**
32
 * Defines the <a href="https://www.postgresql.org/docs/current/">PostgreSQL</a> SQL dialect
33
 */
34
public class PostgreSqlDialect implements Dialect {
35
    private static final EnumSet<Capability> SUPPORTED_CAPS = EnumSet.of(LIMIT_OFFSET, CONCAT_OPERATOR, MODULO_OPERATOR, CURRENT_TIME, NULL_ORDERING, SELECT_FOR_UPDATE, TRUNCATE_TABLE);
30✔
36

37
    /**
38
     * Creates a PostgreSQL {@link Dialect} implementation.
39
     */
40
    public PostgreSqlDialect() {}
3✔
41

42
    @Override
43
    public String getProductName() {
44
        return "PostgreSQL";
2✔
45
    }
46

47
    @Override
48
    public boolean offsetBeforeLimit() {
49
        return true;
2✔
50
    }
51

52
    @Override
53
    public Optional<String> formatRowOffsetClause() {
54
        return Optional.of("offset ?");
3✔
55
    }
56

57
    @Override
58
    public Optional<String> formatRowLimitClause() {
59
        return Optional.of("limit ?");
3✔
60
    }
61

62
    @Override
63
    public Optional<String> formatRowNumLiteral() {
64
        return Optional.empty();
×
65
    }
66

67
    @Override
68
    public String formatToNumberFunction(String operand, int precision, int scale) {
69
        StringBuilder mask = new StringBuilder();
4✔
70
        if (precision-scale > 0) {
4!
71
            mask.append(generate("9", precision-scale));
8✔
72
        }
73
        if (scale > 0) {
2!
74
            mask.append(".").append(generate("9", scale));
×
75
        }
76

77
        return "to_number(" + operand + ", '" + mask + "')";
5✔
78
    }
79

80
    @Override
81
    public String formatToCharFunction(String operand, String format) {
82
        return "to_char(" + operand + ", " + format + ")";
4✔
83
    }
84

85
    @Override
86
    public String formatSubstringFunction(String operand, int startPos, int length) {
87
        return "substring(" + operand + ", " + startPos + ", " + length + ")";
5✔
88
    }
89

90
    @Override
91
    public String formatConcatFunction(List<String> operands) {
92
        throw new UnsupportedOperationException("PostgreSQL does not support the concat() function (use the concat infix operator instead)");
×
93
    }
94

95
    @Override
96
    public String formatLengthFunction(String operand) {
97
        return "char_length(" + operand + ")";
3✔
98
    }
99

100
    @Override
101
    public String formatCeilFunction(String operand) {
102
        return "ceil(" + operand + ")";
3✔
103
    }
104

105
    @Override
106
    public String formatRoundFunction(String operand) {
107
        return "round(" + operand + ")";
3✔
108
    }
109

110
    @Override
111
    public String formatModuloFunction(String divisor, String dividend) {
112
        throw new UnsupportedOperationException("PostgreSQL does not support the mod() function (use the modulo infix operator instead)");
×
113
    }
114

115
    @Override
116
    public String formatCurrentDateFunction() {
117
        return "current_date";
2✔
118
    }
119

120
    @Override
121
    public Optional<String> getConcatOperator() {
122
        return Optional.of("||");
3✔
123
    }
124

125
    @Override
126
    public boolean supports(Capability capability) {
127
        return SUPPORTED_CAPS.contains(capability);
4✔
128
    }
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc