proof concept - access to session variables on client side - Mailing list pgsql-hackers

From Pavel Stehule
Subject proof concept - access to session variables on client side
Date
Msg-id CAFj8pRD+C8oAWEzX999pQg1itbQmfT9X4jjhZdJy2QigWzVMAg@mail.gmail.com
Whole thread Raw
Responses Re: proof concept - access to session variables on client side
Re: proof concept - access to session variables on client side
List pgsql-hackers
Hello

I worked on simple patch, that enable access from server side to
client side data. It add two new hooks to libpq - one for returning of
local context, second for setting of local context.

A motivation is integration of possibilities of psql console together
with stronger language - plpgsql. Second target is enabling
possibility to save a result of some server side process in psql. It
improve vars feature in psql.

pavel ~/src/postgresql/src $ cat test.sql
\echo value of external paremeter is :"myvar"

do $$
begin
  -- we can take any session variable on client side
  -- it is safe against to SQL injection
  raise notice 'external parameter accessed from plpgsql is "%"',
hgetvar('myvar');

  -- we can change this session variable and finish transaction
  perform hsetvar('myvar', 'Hello, World');
end;
$$ language plpgsql;

\echo new value of session variable is :"myvar"

cat test.sql | psql postgres -v myvar=Hello
value of external paremeter is "Hello"
NOTICE:  external parameter accessed from plpgsql is "Hello"
DO
new value of session variable is "Hello, World"

This is just proof concept - there should be better integration with
pl languages, using cache for read on server side, ...

Notices?

Regards

Pavel Stehule

Attachment

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [PATCH] lock_timeout and common SIGALRM framework
Next
From: Amit Kapila
Date:
Subject: Re: new --maintenance-db options