1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
|
---
layout: default_docs
title: Escaped scalar functions
header: Chapter 8. JDBC escapes
resource: media
previoustitle: Date-time escapes
previous: escapes-datetime.html
nexttitle: Chapter 9. PostgreSQL™ Extensions to the JDBC API
next: ext.html
---
The JDBC specification defines functions with an escape call syntax : `{fn function_name(arguments)}`.
The following tables show which functions are supported by the PostgreSQL™ driver.
The driver supports the nesting and the mixing of escaped functions and escaped
values. The appendix C of the JDBC specification describes the functions.
Some functions in the following tables are translated but not reported as supported
because they are duplicating or changing their order of the arguments. While this
is harmless for literal values or columns, it will cause problems when using
prepared statements. For example "`{fn right(?,?)}`" will be translated to "`substring(? from (length(?)+1-?))`".
As you can see the translated SQL requires more parameters than before the
translation but the driver will not automatically handle this.
<a name="escape-numeric-functions-table"></a>
**Table 8.1. Supported escaped numeric functions**
<table summary="Supported escaped numeric functions" class="CALSTABLE" border="1">
<tr>
<th>function</th>
<th>reported as supported</th>
<th>translation</th>
<th>comments</th>
</tr>
<tbody>
<tr>
<td>abs(arg1)</td>
<td>yes</td>
<td>abs(arg1)</td>
<td> </td>
</tr>
<tr>
<td>acos(arg1)</td>
<td>yes</td>
<td>acos(arg1)</td>
<td> </td>
</tr>
<tr>
<td>asin(arg1)</td>
<td>yes</td>
<td>asin(arg1)</td>
<td> </td>
</tr>
<tr>
<td>atan(arg1)</td>
<td>yes</td>
<td>atan(arg1)</td>
<td> </td>
</tr>
<tr>
<td>atan2(arg1,arg2)</td>
<td>yes</td>
<td>atan2(arg1,arg2)</td>
<td> </td>
</tr>
<tr>
<td>ceiling(arg1)</td>
<td>yes</td>
<td>ceil(arg1)</td>
<td> </td>
</tr>
<tr>
<td>cos(arg1)</td>
<td>yes</td>
<td>cos(arg1)</td>
<td> </td>
</tr>
<tr>
<td>cot(arg1)</td>
<td>yes</td>
<td>cot(arg1)</td>
<td> </td>
</tr>
<tr>
<td>degrees(arg1)</td>
<td>yes</td>
<td>degrees(arg1)</td>
<td> </td>
</tr>
<tr>
<td>exp(arg1)</td>
<td>yes</td>
<td>exp(arg1)</td>
<td> </td>
</tr>
<tr>
<td>floor(arg1)</td>
<td>yes</td>
<td>floor(arg1)</td>
<td> </td>
</tr>
<tr>
<td>log(arg1)</td>
<td>yes</td>
<td>ln(arg1)</td>
<td> </td>
</tr>
<tr>
<td>log10(arg1)</td>
<td>yes</td>
<td>log(arg1)</td>
<td> </td>
</tr>
<tr>
<td>mod(arg1,arg2)</td>
<td>yes</td>
<td>mod(arg1,arg2)</td>
<td> </td>
</tr>
<tr>
<td>pi(arg1)</td>
<td>yes</td>
<td>pi(arg1)</td>
<td> </td>
</tr>
<tr>
<td>power(arg1,arg2)</td>
<td>yes</td>
<td>pow(arg1,arg2)</td>
<td> </td>
</tr>
<tr>
<td>radians(arg1)</td>
<td>yes</td>
<td>radians(arg1)</td>
<td> </td>
</tr>
<tr>
<td>rand()</td>
<td>yes</td>
<td>random()</td>
<td> </td>
</tr>
<tr>
<td>rand(arg1)</td>
<td>yes</td>
<td>setseed(arg1)*0+random()</td>
<td>The seed is initialized with the given argument and a new randow value is returned.</td>
</tr>
<tr>
<td>round(arg1,arg2)</td>
<td>yes</td>
<td>round(arg1,arg2)</td>
<td> </td>
</tr>
<tr>
<td>sign(arg1)</td>
<td>yes</td>
<td>sign(arg1)</td>
<td> </td>
</tr>
<tr>
<td>sin(arg1)</td>
<td>yes</td>
<td>sin(arg1)</td>
<td> </td>
</tr>
<tr>
<td>sqrt(arg1)</td>
<td>yes</td>
<td>sqrt(arg1)</td>
<td> </td>
</tr>
<tr>
<td>tan(arg1)</td>
<td>yes</td>
<td>tan(arg1)</td>
<td> </td>
</tr>
<tr>
<td>truncate(arg1,arg2)</td>
<td>yes</td>
<td>trunc(arg1,arg2)</td>
<td> </td>
</tr>
</tbody>
</table>
<a name="escape-string-functions-table"></a>
**Table 8.2. Supported escaped string functions**
<table summary="Supported escaped string functions" class="CALSTABLE" border="1">
<tr>
<th>function</th>
<th>reported as supported</th>
<th>translation</th>
<th>comments</th>
</tr>
<tbody>
<tr>
<td>ascii(arg1)</td>
<td>yes</td>
<td>ascii(arg1)</td>
<td> </td>
</tr>
<tr>
<td>char(arg1)</td>
<td>yes</td>
<td>chr(arg1)</td>
<td> </td>
</tr>
<tr>
<td>concat(arg1,arg2...)</td>
<td>yes</td>
<td>(arg1||arg2...)</td>
<td>The JDBC specification
only require the two arguments version, but supporting more arguments
was so easy...</td>
</tr>
<tr>
<td>insert(arg1,arg2,arg3,arg4)</td>
<td>no</td>
<td>overlay(arg1 placing arg4 from arg2 for arg3)</td>
<td>This function is not reported as supported since it changes
the order of the arguments which can be a problem (for prepared
statements by example).</td>
</tr>
<tr>
<td>lcase(arg1)</td>
<td>yes</td>
<td>lower(arg1)</td>
<td> </td>
</tr>
<tr>
<td>left(arg1,arg2)</td>
<td>yes</td>
<td>substring(arg1 for arg2)</td>
<td> </td>
</tr>
<tr>
<td>length(arg1)</td>
<td>yes</td>
<td>length(trim(trailing from arg1))</td>
<td> </td>
</tr>
<tr>
<td>locate(arg1,arg2)</td>
<td>no</td>
<td>position(arg1 in arg2)</td>
<td> </td>
</tr>
<tr>
<td>locate(arg1,arg2,arg3)</td>
<td>no</td>
<td>(arg2*sign(position(arg1 in substring(arg2 from
arg3)+position(arg1 in substring(arg2 from arg3))</td>
<td>Not reported as supported since the three arguments version
duplicate and change the order of the arguments.</td>
</tr>
<tr>
<td>ltrim(arg1)</td>
<td>yes</td>
<td>trim(leading from arg1)</td>
<td> </td>
</tr>
<tr>
<td>repeat(arg1,arg2)</td>
<td>yes</td>
<td>repeat(arg1,arg2)</td>
<td> </td>
</tr>
<tr>
<td>replace(arg1,arg2,arg3)</td>
<td>yes</td>
<td>replace(arg1,arg2,arg3)</td>
<td>Only reported as supported by 7.3 and above servers.</td>
</tr>
<tr>
<td>right(arg1,arg2)</td>
<td>no</td>
<td>substring(arg1 from (length(arg1)+1-arg2))</td>
<td>Not reported as supported since arg2 is duplicated.</td>
</tr>
<tr>
<td>rtrim(arg1)</td>
<td>yes</td>
<td>trim(trailing from arg1)</td>
<td> </td>
</tr>
<tr>
<td>space(arg1)</td>
<td>yes</td>
<td>repeat(' ',arg1)</td>
<td> </td>
</tr>
<tr>
<td>substring(arg1,arg2)</td>
<td>yes</td>
<td>substr(arg1,arg2)</td>
<td> </td>
</tr>
<tr>
<td>substring(arg1,arg2,arg3)</td>
<td>yes</td>
<td>substr(arg1,arg2,arg3)</td>
<td> </td>
</tr>
<tr>
<td>ucase(arg1)</td>
<td>yes</td>
<td>upper(arg1)</td>
<td> </td>
</tr>
<tr>
<td>soundex(arg1)</td>
<td>no</td>
<td>soundex(arg1)</td>
<td>Not reported as supported since it requires the fuzzystrmatch
contrib module.</td>
</tr>
<tr>
<td>difference(arg1,arg2)</td>
<td>no</td>
<td>difference(arg1,arg2)</td>
<td>Not reported as supported since it requires the fuzzystrmatch
contrib module.</td>
</tr>
</tbody>
</table>
<a name="escape-datetime-functions-table"></a>
**Table 8.3. Supported escaped date/time functions**
<table summary="Supported escaped date/time functions" class="CALSTABLE" border="1">
<tr>
<th>function</th>
<th>reported as supported</th>
<th>translation</th>
<th>comments</th>
</tr>
<tbody>
<tr>
<td>curdate()</td>
<td>yes</td>
<td>current_date</td>
<td> </td>
</tr>
<tr>
<td>curtime()</td>
<td>yes</td>
<td>current_time</td>
<td> </td>
</tr>
<tr>
<td>dayname(arg1)</td>
<td>yes</td>
<td>to_char(arg1,'Day')</td>
<td> </td>
</tr>
<tr>
<td>dayofmonth(arg1)</td>
<td>yes</td>
<td>extract(day from arg1)</td>
<td> </td>
</tr>
<tr>
<td>dayofweek(arg1)</td>
<td>yes</td>
<td>extract(dow from arg1)+1</td>
<td>We must add 1 to be in the expected 1-7 range.</td>
</tr>
<tr>
<td>dayofyear(arg1)</td>
<td>yes</td>
<td>extract(doy from arg1)</td>
<td> </td>
</tr>
<tr>
<td>hour(arg1)</td>
<td>yes</td>
<td>extract(hour from arg1)</td>
<td> </td>
</tr>
<tr>
<td>minute(arg1)</td>
<td>yes</td>
<td>extract(minute from arg1)</td>
<td> </td>
</tr>
<tr>
<td>month(arg1)</td>
<td>yes</td>
<td>extract(month from arg1)</td>
<td> </td>
</tr>
<tr>
<td>monthname(arg1)</td>
<td>yes</td>
<td>to_char(arg1,'Month')</td>
<td> </td>
</tr>
<tr>
<td>now()</td>
<td>yes</td>
<td>now()</td>
<td> </td>
</tr>
<tr>
<td>quarter(arg1)</td>
<td>yes</td>
<td>extract(quarter from arg1)</td>
<td> </td>
</tr>
<tr>
<td>second(arg1)</td>
<td>yes</td>
<td>extract(second from arg1)</td>
<td> </td>
</tr>
<tr>
<td>week(arg1)</td>
<td>yes</td>
<td>extract(week from arg1)</td>
<td> </td>
</tr>
<tr>
<td>year(arg1)</td>
<td>yes</td>
<td>extract(year from arg1)</td>
<td> </td>
</tr>
<tr>
<td>timestampadd(argIntervalType,argCount,argTimeStamp)</td>
<td>yes</td>
<td>('(interval according to argIntervalType and
argCount)'+argTimeStamp)</td>
<td>an argIntervalType value of SQL_TSI_FRAC_SECOND
is not implemented since backend does not support it</td>
</tr>
<tr>
<td>timestampdiff(argIntervalType,argTimeStamp1,argTimeStamp2)</td>
<td>not</td>
<td>extract((interval according to argIntervalType) from
argTimeStamp2-argTimeStamp1 )</td>
<td>only an argIntervalType value of SQL_TSI_FRAC_SECOND, SQL_TSI_FRAC_MINUTE, SQL_TSI_FRAC_HOUR
or SQL_TSI_FRAC_DAY is supported </td>
</tr>
</tbody>
</table>
<a name="escape-misc-functions-table"></a>
**Table 8.4. Supported escaped misc functions**
<table summary="Supported escaped misc functions" class="CALSTABLE" border="1">
<tr>
<th>function</th>
<th>reported as supported</th>
<th>translation</th>
<th>comments</th>
</tr>
<tbody>
<tr>
<td>database()</td>
<td>yes</td>
<td>current_database()</td>
<td>Only reported as supported by 7.3 and above servers.</td>
</tr>
<tr>
<td>ifnull(arg1,arg2)</td>
<td>yes</td>
<td>coalesce(arg1,arg2)</td>
<td> </td>
</tr>
<tr>
<td>user()</td>
<td>yes</td>
<td>user</td>
<td> </td>
</tr>
</tbody>
</table>
|