|
PostgreSQL: Advanced SQL: Functions
- Supports many languages: SQL, PL/PgSQL, C, PL/Java, PL/Tcl, PL/Python, PL/Ruby, PL/R, PL/PHP ...
- C - complete access to the system, through SPI and call framework
- PL/PgSQL - Block based language, looks like SQL, loops, conditions
01 CREATE [ OR REPLACE ] FUNCTION name ( [ argtype [, ...] ] )
02 RETURNS rettype
03 { LANGUAGE langname
04 | IMMUTABLE | STABLE | VOLATILE
05 | CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT
06 }
- IMMUTABLE = function returns the same result on the same input: eg: sin()
- STABLE = within a single transaction, the function will return the same result on the same input: eg: time_at_start_of_txn()
- VOLATILE = function may return different result on same input: eg: random()
- CALLED ON NULL INPUT = (default) Call when one or more arguments to function are NULL
- RETURNS NULL ON NULL INPUT | STRICT = the function always returns NULL if any arguments are NULL
Page 30
|