The pg_variables extension defines pgv_set and pgv_get functions for scalar variables, and several functions for record type. The variables are accessable only inside the session context. Variables are transaction indendent. Support for transactions and savepoints is planned for Postres Pro 11.
Variables can be used for storing session data, caching query results etc. In multiple cases they can be an effective replacement for temporary tables.