Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id 9C5B79FB232 for ; Tue, 14 Nov 2006 14:43:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 64063-01 for ; Tue, 14 Nov 2006 14:43:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id C21249FA4E5 for ; Tue, 14 Nov 2006 14:43:10 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from presinet.com (mail.presinet.com [209.53.156.1]) by svr4.postgresql.org (Postfix) with ESMTP id 03F9E5AF88E for ; Tue, 14 Nov 2006 18:43:09 +0000 (GMT) Received: from [10.10.1.151] ([10.10.1.151]) by presinet.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 14 Nov 2006 10:39:52 -0800 Message-ID: <455A0E36.1050809@presinet.com> Date: Tue, 14 Nov 2006 10:43:02 -0800 From: Bricklen Anderson User-Agent: Thunderbird 1.5.0.7 (X11/20060922) MIME-Version: 1.0 To: Luca Ferrari Cc: pgsql-sql@postgresql.org Subject: Re: hiding column values for specific rows References: <200611131411.50562.fluca1978@infinito.it> In-Reply-To: <200611131411.50562.fluca1978@infinito.it> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 14 Nov 2006 18:39:52.0546 (UTC) FILETIME=[45BCDC20:01C7081C] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200611/149 X-Sequence-Number: 26801 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.