|
FunctionsFunction Evaluation
ExamplesFactorial FunctionThere is only one factorial function defined in the pg_proc catalog. So the following query automatically converts the int2 argument to int4: tgl=> select int4fac(int2 '4'); int4fac --------- 24 (1 row)and is actually transformed by the parser to tgl=> select int4fac(int4(int2 '4')); int4fac --------- 24 (1 row) Substring FunctionThere are two substr functions declared in pg_proc. However, only one takes two arguments, of types text and int4. If called with a string constant of unspecified type, the type is matched up directly with the only candidate function type: tgl=> select substr('1234', 3); substr -------- 34 (1 row) If the string is declared to be of type varchar, as might be the case if it comes from a table, then the parser will try to coerce it to become text: tgl=> select substr(varchar '1234', 3); substr -------- 34 (1 row)which is transformed by the parser to become tgl=> select substr(text(varchar '1234'), 3); substr -------- 34 (1 row)
And, if the function is called with an int4, the parser will try to convert that to text: tgl=> select substr(1234, 3); substr -------- 34 (1 row)actually executes as tgl=> select substr(text(1234), 3); substr -------- 34 (1 row) |
|||||||||||||||||
With any suggestions or questions please feel free to contact us |