From: Bricklen Anderson <banderson@presinet.com>
To: Luca Ferrari <fluca1978@infinito.it>
Cc: pgsql-sql@postgresql.org
Subject: Re: hiding column values for specific rows
Date: Tue, 14 Nov 2006 10:43:02 -0800
Message-ID: <455A0E36.1050809@presinet.com> (raw)
In-Reply-To: <200611131411.50562.fluca1978@infinito.it>
References: <200611131411.50562.fluca1978@infinito.it>
Luca Ferrari wrote:
> Hi,
> I don't know if this's possible but I'd like to hide column values for
> specific rows within a query. Imagine I've got a table with columns username
> and password: users(username,password). Now I'd like the user registered in
> the table to see her password, to see who is registered but not to see the
> other people passwords. For example, if the table contains:
> username | password
> --------------+-------------
> luca | myPaswd
> roberto | otherPaswd
> gianna | thirdPaswd
>
> I'd like to do a query like: "SELECT * FROM users where username=luca"
> obtaining something like:
> username | password
> --------------+-------------
> luca | myPaswd
> roberto | xxxxx
> gianna | XXXXX
>
> Is it possible to specify in the above query that all password columns that do
> not belong to selected row (username=luca) must be hidden? Anyone has an idea
> about how to implement this on the database side?
>
> Thanks,
> Luca
>
You could try:
select username,case when username='luca' then password else 'XXXXXX'
end as password from users;
Note that the the username 'luca' corresponds to the user querying the
table.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: banderson@presinet.com, fluca1978@infinito.it
Subject: Re: hiding column values for specific rows
In-Reply-To: <455A0E36.1050809@presinet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox