Re: Controlling complexity in queries

From: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Controlling complexity in queries
Date: 2011-12-15 09:37:01
Message-ID: 86ty52xjk2.fsf@protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jay Levitt <jay(dot)levitt(at)gmail(dot)com> writes:

> * You want contextual queries.
>
> (I guess this is a special case of "you need non relational features".)
>
> In my case, I want all queries against content to be filtered by their
> relevance to the current user. That can't go into a view, because
> views don't have parameters; I need a computed column that may be
> different every time I run the query, and depends on a piece of
> information (the current user ID) that Postgres can't know.

How about the following:

CREATE TABLE test1 (
id serial NOT NULL,
username text NOT NULL,
value text NOT NULL,
PRIMARY KEY (id)
);

COPY test1 (username, value) FROM stdin DELIMITER '|';
user1|user1_1
user1|user1_2
user2|user2_1
user2|user2_2
user2|user2_3
\.

CREATE VIEW test1v AS
SELECT id, username, value
FROM test1
WHERE username = current_user;

Here the result of "SELECT * FROM test1v" depends on who issued the query.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas 2011-12-15 09:49:59 Re: Philosophical question
Previous Message Guillaume Lelarge 2011-12-15 09:24:50 Re: question about \encoding option of psql