May
19
2009
Writing a function for frequently used SQL (returning custom columns) in PostgreSQL
Posted by Chirag Patel in Code SnippetsThere’s no real easy way to do this, but I’d like to write a database function (in this case a PL/pgSQL function) to run a SQL SELECT statement with custom columns in the output.
First, you need to create a custom data type for the custom columns (apparently, this step won’t be necessary when PostgreSQL 8.4 supports the RETURNS TABLE syntax in functions). For example
Tags: custom, data type, function, pl/pgsql, PostgreSQL, psql, select, table








Entries (RSS)