Last year I worked on few successful projects - with Alvaro Herrera I finished
XMLTABLE
. I materialized my ideas about better user interface and I wrote pspg pager. Now, I am working on implementation of session variables. There are lot of concepts: MSSQL, Oracle, DB2 has own based on history, with advantages and disadvantages. I am working on schema variables, where session variables are joined to schema like tables, views, ... This concept is pretty strong. We can limit access by rights to schema, to object self. We can share variables across complete PostgreSQL environment - psql, PL languages, SQL. Maybe in next versions, the schema variables can holds constraints and triggers. I have workable prototype - now only scalar types are supported, but I hope so support of composite types will be early.postgres=# CREATE VARIABLE foo AS numeric;The schema variables are persistent database object, but the content self is temporal. The analogy can be Oracle's global temporary tables.
CREATE VARIABLE
postgres=# LET foo = 100;
LET
postgres=# SELECT foo;
┌─────┐
│ foo │
╞═════╡
│ 100 │
└─────┘
(1 row)
postgres=# DO $$
postgres$# BEGIN
postgres$# RAISE NOTICE '%', foo;
postgres$# END;
postgres$# $$;
NOTICE: 100
DO
postgres=# GRANT SELECT ON foo TO public;
GRANT
postgres=# LET foo = (SELECT count(*) FROM pg_class);
LET
postgres=# SELECT foo;
┌─────┐
│ foo │
╞═════╡
│ 344 │
└─────┘
(1 row)
postgres=# SELECT * FROM generate_series(1,1000) g(i) WHERE i = foo;
┌─────┐
│ i │
╞═════╡
│ 344 │
└─────┘
(1 row)
postgres=# SELECT * FROM generate_series(1,1000) g(i) WHERE i = public.foo;
┌─────┐
│ i │
╞═════╡
│ 344 │
└─────┘
(1 row)