Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b0V1x-0004v7-9I for pgsql-sql@arkaria.postgresql.org; Wed, 11 May 2016 14:22:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b0V1w-0001UJ-SA for pgsql-sql@arkaria.postgresql.org; Wed, 11 May 2016 14:22:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b0V1v-0001QF-15 for pgsql-sql@postgresql.org; Wed, 11 May 2016 14:22:27 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b0V1n-0000oe-Ud for pgsql-sql@postgresql.org; Wed, 11 May 2016 14:22:26 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id E8D1220FE6 for ; Wed, 11 May 2016 10:22:16 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute2.internal (MEProxy); Wed, 11 May 2016 10:22:16 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=9GMIKq2kVuzpCScPwnLjBcD1Lsc=; b=oW2Ueo AXdIbz2XJuFR4s3g3plzf+H3otAdf2JE1j3Fj3jNlgpEnL9LTJS2uZoh5gyo0A7j CWeZVl7cr2DmYKoq8C9f3skP5yXL3u4qyArXwUJW+jfZQjMMZb/Yd8bl2PY+iheg Tacsr23rzXrU5dmZNvJVjKSaMRklsUzVkOkzU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=9GMIKq2kVuzpCSc PwnLjBcD1Lsc=; b=qrUaNT1m6ZMxdzCAxrLVhP/J+dxLvbxoJP0SnBrwU5DiRL8 FlCMqphO6UOR+sZWM7GOu5t7BZOZDidbMvC07esUAaDNoRraJaq8oLrXKBbrYcat tlNpxkejAtBmxRMhU19IwDhQkLmNgKI5uujTU2+bgWWBHXMVXrTAF0t5j9Xo= X-Sasl-enc: G/E4NOzWie4L2JVApCKhplE9W7exIpf0z1AY98GIgmyX 1462976536 Received: from [192.168.1.2] (174-24-160-10.tukw.qwest.net [174.24.160.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 63F30680109; Wed, 11 May 2016 10:22:16 -0400 (EDT) Subject: Re: Create a trigger only for certain users To: Ezequiel Luis Pellettieri , pgsql-sql@postgresql.org References: From: Adrian Klaver Message-ID: Date: Wed, 11 May 2016 07:22:15 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 05/11/2016 07:12 AM, Ezequiel Luis Pellettieri wrote: > Hi guys, I'm going to build a trigger on update for a few tables, but I > have to ignore updates for certain users. Is there a way to accomplish > this task? A thought, assuming plpgsql: 1) Use session_user/current_user: http://www.postgresql.org/docs/9.5/interactive/functions-info.html 2) In BEFORE trigger code: http://www.postgresql.org/docs/9.5/interactive/plpgsql-trigger.html test for the user and return NULL if there is a match: "Row-level triggers fired BEFORE can return null to signal the trigger manager to skip the rest of the operation for this row (i.e., subsequent triggers are not fired, and the INSERT/UPDATE/DELETE does not occur for this row)." Another thought, assuming Postgres 9.5+: Use Row Level Security: http://www.postgresql.org/docs/9.5/static/sql-createpolicy.html > > Thanks in advance. > > Regards. > Pelle.- > > -- > * > * > * > * > * > * -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql