Thread: server variables ?

server variables ?

From
Andreas
Date:
Hi,

are there something like variables on the server-side that can be set by
the client?

e.g. I'd like to store the user-id who created or updated a record.
I've allready got a trigger that sets a timestamp whenever a record is
updated. It was cute if I could let this triggers store the user-id, too.

I'd like to open a connection when the client application starts.
The client should set a variable  userid  within this connection and
every trigger would know who uses this connection right now.

BTW ... How would I use this variable as a DEFAULT value when it should
be set just at the creation time of the record?
something like a collumn:
...
created_by_fk   integer   not null   default userid,
...

How could I use such a variables value in views?


Re: server variables ?

From
"A. Kretschmer"
Date:
am  Thu, dem 12.04.2007, um  5:33:30 +0200 mailte Andreas folgendes:
> Hi,
>
> are there something like variables on the server-side that can be set by
> the client?
>
> e.g. I'd like to store the user-id who created or updated a record.
> I've allready got a trigger that sets a timestamp whenever a record is
> updated. It was cute if I could let this triggers store the user-id, too.

If you mean with user-id the name of the current user, just use
current_user.


>
> I'd like to open a connection when the client application starts.
> The client should set a variable  userid  within this connection and
> every trigger would know who uses this connection right now.
>
> BTW ... How would I use this variable as a DEFAULT value when it should
> be set just at the creation time of the record?
> something like a collumn:
> ...
> created_by_fk   integer   not null   default userid,
                  text                 default current_user



> ...
>
> How could I use such a variables value in views?

select ... from your_view where created_by_fk = current_user



Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

Re: server variables ?

From
Andreas
Date:
I've got a user table for my client application and the userid variable
I'd like to set would be a value of the primary-key column and those are
integers.
I'd rather store a numeric id than the current_user as a varchar for
efficiency reasons. Even a 1 byte integer would be enough.



A. Kretschmer schrieb:
> am  Thu, dem 12.04.2007, um  5:33:30 +0200 mailte Andreas folgendes:
>
>> are there something like variables on the server-side that can be set by
>> the client?
>>
>> e.g. I'd like to store the user-id who created or updated a record.
>> I've allready got a trigger that sets a timestamp whenever a record is
>> updated. It was cute if I could let this triggers store the user-id, too.
>>
>
> If you mean with user-id the name of the current user, just use
> current_user.
>
>
>
>> I'd like to open a connection when the client application starts.
>> The client should set a variable  userid  within this connection and
>> every trigger would know who uses this connection right now.
>>
>> BTW ... How would I use this variable as a DEFAULT value when it should
>> be set just at the creation time of the record?
>> something like a collumn:
>> ...
>> created_by_fk   integer   not null   default userid,
>>
>                   text                 default current_user
>
>
>
>
>> ...
>>
>> How could I use such a variables value in views?
>>
>
> select ... from your_view where created_by_fk = current_user
>
>
>
> Andreas
>