JDBC规范定义了调用语法的溢出函数:{fn
function_name(arguments)}。下表列出PostgresSQL™ 驱动程序支持的函数。驱动程序支持嵌套和混合的溢出函数和溢出值。附录C
JDBC规范详述了这些函数。
下表中的某些函数已经转化,但是没有reported
as supported,因为它们的主题重复或者顺序改变了。虽然对字面上的值或者数字是无害的,但是在使用prepared
statements时会引起问题。例如,"{fn
right(?,?)}"将被转化为
"substring(? from (length(?)+1-?))"。如你所见,转化后的SQL比转换前要求更多的参数,而驱动程序不能自动处理这个。
表8.1
支持的数字函数溢出
|
function |
reported
as supported |
translation |
comments |
|
abs(arg1) |
yes |
abs(arg1) |
|
|
acos(arg1) |
yes |
acos(arg1) |
|
|
asin(arg1) |
yes |
asin(arg1) |
|
|
atan(arg1) |
yes |
atan(arg1) |
|
|
atan2(arg1,arg2) |
yes |
atan2(arg1,arg2) |
|
|
ceiling(arg1) |
yes |
ceil(arg1) |
|
|
cos(arg1) |
yes |
cos(arg1) |
|
|
cot(arg1) |
yes |
cot(arg1) |
|
|
degrees(arg1) |
yes |
degrees(arg1) |
|
|
exp(arg1) |
yes |
exp(arg1) |
|
|
floor(arg1) |
yes |
floor(arg1) |
|
|
log(arg1) |
yes |
ln(arg1) |
|
|
log10(arg1) |
yes |
log(arg1) |
|
|
mod(arg1,arg2) |
yes |
mod(arg1,arg2) |
|
|
pi(arg1) |
yes |
pi(arg1) |
|
|
power(arg1,arg2) |
yes |
pow(arg1,arg2) |
|
|
radians(arg1) |
yes |
radians(arg1) |
|
|
rand() |
yes |
random() |
|
|
rand(arg1) |
yes |
setseed(arg1)*0+random() |
The seed is initialized with the
given argument and a new randow value is returned. |
|
round(arg1,arg2) |
yes |
round(arg1,arg2) |
|
|
sign(arg1) |
yes |
sign(arg1) |
|
|
sin(arg1) |
yes |
sin(arg1) |
|
|
sqrt(arg1) |
yes |
sqrt(arg1) |
|
|
tan(arg1) |
yes |
tan(arg1) |
|
|
truncate(arg1,arg2) |
yes |
trunc(arg1,arg2) |
|
表8.2
支持的字符串溢出
|
function |
reported
as supported |
translation |
comments |
|
ascii(arg1) |
yes |
ascii(arg1) |
|
|
char(arg1) |
yes |
chr(arg1) |
|
|
concat(arg1,arg2...) |
yes |
(arg1||arg2...) |
The JDBC
specification only require the two arguments version, but supporting more
arguments was so easy... |
|
insert(arg1,arg2,arg3,arg4) |
no |
overlay(arg1 placing arg4 from
arg2 for arg3) |
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). |
|
lcase(arg1) |
yes |
lower(arg1) |
|
|
left(arg1,arg2) |
yes |
substring(arg1 for arg2) |
|
|
length(arg1) |
yes |
length(trim(trailing from arg1)) |
|
|
locate(arg1,arg2) |
no |
position(arg1 in arg2) |
|
|
locate(arg1,arg2,arg3) |
no |
(arg2*sign(position(arg1 in
substring(arg2 from arg3)+position(arg1 in substring(arg2 from arg3)) |
Not reported as supported since
the three arguments version duplicate and change the order of the
arguments. |
|
ltrim(arg1) |
yes |
trim(leading from arg1) |
|
|
repeat(arg1,arg2) |
yes |
repeat(arg1,arg2) |
|
|
replace(arg1,arg2,arg3) |
yes |
replace(arg1,arg2,arg3) |
Only reported as supported by 7.3
and above servers. |
|
right(arg1,arg2) |
no |
substring(arg1 from
(length(arg1)+1-arg2)) |
Not reported as supported since
arg2 is duplicated. |
|
rtrim(arg1) |
yes |
trim(trailing from arg1) |
|
|
space(arg1) |
yes |
repeat(' ',arg1) |
|
|
substring(arg1,arg2) |
yes |
substr(arg1,arg2) |
|
|
substring(arg1,arg2,arg3) |
yes |
substr(arg1,arg2,arg3) |
|
|
ucase(arg1) |
yes |
upper(arg1) |
|
|
soundex(arg1) |
no |
soundex(arg1) |
Not reported as supported since it
requires the fuzzystrmatch contrib module. |
|
difference(arg1,arg2) |
no |
difference(arg1,arg2) |
Not reported as supported since it
requires the fuzzystrmatch contrib module. |
表8.3
支持的date/time函数溢出
|
function |
reported
as supported |
translation |
comments |
|
curdate() |
yes |
current_date |
|
|
curtime() |
yes |
current_time |
|
|
dayname(arg1) |
yes |
to_char(arg1,'Day') |
|
|
dayofmonth(arg1) |
yes |
extract(day from arg1) |
|
|
dayofweek(arg1) |
yes |
extract(dow from arg1)+1 |
We must add 1 to be in the
expected 1-7 range. |
|
dayofyear(arg1) |
yes |
extract(doy from arg1) |
|
|
hour(arg1) |
yes |
extract(hour from arg1) |
|
|
minute(arg1) |
yes |
extract(minute from arg1) |
|
|
month(arg1) |
yes |
extract(month from arg1) |
|
|
monthname(arg1) |
yes |
to_char(arg1,'Month') |
|
|
now() |
yes |
now() |
|
|
quarter(arg1) |
yes |
extract(quarter from arg1) |
|
|
second(arg1) |
yes |
extract(second from arg1) |
|
|
week(arg1) |
yes |
extract(week from arg1) |
|
|
year(arg1) |
yes |
extract(year from arg1) |
|
|
|
|
|
|
8.4
支持的其他混合函数溢出
|
function |
reported
as supported |
translation |
comments |
|
database() |
yes |
current_database() |
Only reported as supported by 7.3
and above servers. |
|
ifnull(arg1,arg2) |
yes |
coalesce(arg1,arg2) |
|
|
user() |
yes |
user |
|