Re: Client's variables - Mailing list pgsql-general

From Marek Lewczuk
Subject Re: Client's variables
Date
Msg-id 41F001E7.50903@lewczuk.com
Whole thread Raw
In response to Client's variables  ("fryk" <fryk@tlen.pl>)
Responses Re: Client's variables  (Richard Huxton <dev@archonet.com>)
List pgsql-general
fryk napisał(a):
> Hi,
>
> How to set such variable after (during?) client connection (PHP)?
>
> I want to use it in view - so view could depends on it:
>
> If I could set client's variable i.e. MY_VAR='hello' then I could do
> something like this:
>
> CREATE VIEW my_view AS SELECT * FROM pg_tables WHERE tablename ~* (SELECT
> MY_VAR FROM ???)

You have (at least) two choices. First is to use temporary table, where
you can store anything you wish and it will be visible and available for
current connection/session.

Read more:
http://www.postgresql.org/docs/8.0/interactive/sql-createtable.html

Another solution is to use plperl - this is more flexible then the first
one. plperl supports global values - go to:
http://www.postgresql.org/docs/8.0/interactive/plperl-global.html
and see examples set_var and get_var.

You decide what is the best solution for your needs.


In Polish:
Masz dwa wyjścia. Pierwszy wykorzystać tablice tymczasową, w której
możesz trzymać co chcesz. Będzie ona widoczna tylko dla jednego
użytkownika w obecnej sesji/połączeniu. Zobacz więcej:
http://www.postgresql.org/docs/8.0/interactive/sql-createtable.html

Drugie rozwiązanie to skorzystać z plperl'a - to jest bardziej
elastyczne rozwiązanie. Plperl posiada możliwość tworzenia globalnych
zmiennych. Zobacz więcej:
http://www.postgresql.org/docs/8.0/interactive/plperl-global.html
Masz tam przykładowe funkcje, które możesz śmiało wykorzystać.

Sam zdecyduj co jest lepszym rozwiązaniem w Twojej aplikacji.


ML



pgsql-general by date:

Previous
From: "Dann Corbit"
Date:
Subject: Re: Unique Index
Next
From: Stephan Szabo
Date:
Subject: Re: Unique Index