Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Databases - Practical PostgreSQL
Previous Page Home Next Page

Using Functions

To use a function in a SQL statement, type the function's name, followed by its list of parameters (called arguments ), if any. The arguments passed to a function are enclosed in parentheses. There are two general styles of entering arguments: the standard SQL92 functions are generally implemented so that they accept their arguments delimited by special SQL keywords, such as FROM, FOR, and USING. PostgreSQL-style functions, on the other hand, accept arguments delimited by commas (which you might expect if you have experience with a programming language such as C).

Arguments may be constants, valid identifiers, or expressions. The particular arguments you need to pass to a function will depend completely on the function being used, and its requirements: especially with regards to data types. With a couple of exceptions, all functions require the open and closing parentheses following the function name, even if no arguments are passed.

  
sql92_style_function
 ( { 
argument
 | 
KEYWORD
 } [...] )
  
pgsql_style_function
 ( 
argument
 [, ...] )

Note: The exceptions to the parenthetical function syntax are the SQL92 functions current_date, current_time, and current_timestamp. These lack parentheses to remain compatible with the SQL92 specification.

A powerful use of functions is that they may be nested, provided that the data type returned by a nested function is compatible with the argument accepted by the function it is nested within. Functions may be nested to any depth:

  
function_name
 ( 
nested_function_name
 ( 
arguments
 [, ...] ) [, ...] )

PostgreSQL defines a rich set of functions for its built-in data types. To view a complete list of functions available, execute the \df slash command within psql . PostgreSQL also supports extensibility of its function set through the CREATE FUNCTION command. See Chapter 7 for more on this topic.

Note: The default name for a column that is described by a function in the target list will be the name of the function, without trailing parentheses, or arguments (e.g., to_char).

Databases - Practical PostgreSQL
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire