Re: limiting access to (through) views

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Glenn MacGregor <gtm(at)oracom(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: limiting access to (through) views
Date: 2002-01-16 15:17:04
Message-ID: 20020116071522.X43837-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, 16 Jan 2002, Glenn MacGregor wrote:

> Hi All,
>
> I need to limit access to certain rows of a table. It was suggested
> to do this via a view, but it seems to me that I need the current
> username that is logged in to do this. Also I need to get info from
> another table inorder to make this work. Can I have multiple selects
> in a single view using the output of one in another?
>
> Example:
>
> table1:
> col1,col2,col3
>
> table1 Data:
> test,here,max
> test1,here1,me
> test2,here2,one
> test3,here3,max
> test4,here4,one
> test5,here5,two
>
> table2:
> username,key
>
> table2 Data:
> user1,max
> user2,one
> user3,two
> user4,me
>
> So I have these two tables, I authenticate and gain access to the db.
> How do I know who I am in a query? I need to query table2 for the key
> of the username I am. Then I need to query table1 for rows that col3
> matches the key I got from the previous query.
>
> Is this possable with a view?

CURRENT_USER should give the current user name.
Hmm for the above maybe...

select table1.* from
table1, table2 where
table1.col3=table2.key and
table2.username=CURRENT_USER;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2002-01-16 15:23:14 Re: limiting access to (through) views
Previous Message Stephan Szabo 2002-01-16 15:14:24 Re: Long-running DELETE