Re: Controlling complexity in queries - Mailing list pgsql-general

From Harald Fuchs
Subject Re: Controlling complexity in queries
Date
Msg-id 86ty52xjk2.fsf@protecting.net
Whole thread Raw
In response to Controlling complexity in queries  (Robert James <srobertjames@gmail.com>)
Responses Re: Controlling complexity in queries
List pgsql-general
Jay Levitt <jay.levitt@gmail.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.

pgsql-general by date:

Previous
From: Guillaume Lelarge
Date:
Subject: Re: question about \encoding option of psql
Next
From: Andreas
Date:
Subject: Re: Philosophical question