Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cHqIh-00068E-Ne for pgsql-sql@arkaria.postgresql.org; Fri, 16 Dec 2016 11:03:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cHqIh-0001kq-1P for pgsql-sql@arkaria.postgresql.org; Fri, 16 Dec 2016 11:03:43 +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 1cHqHi-0008CI-SQ for pgsql-sql@postgresql.org; Fri, 16 Dec 2016 11:02:42 +0000 Received: from hub.ringways.co.uk ([88.211.105.30] helo=ringways.co.uk) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cHqHg-00087W-5e for pgsql-sql@postgresql.org; Fri, 16 Dec 2016 11:02:42 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115]) by ringways.co.uk with esmtp (Exim 4.84_2) (envelope-from ) id 1cHqHd-000QO1-OT for pgsql-sql@postgresql.org; Fri, 16 Dec 2016 11:02:38 +0000 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: simple "select / if found" isn't Date: Fri, 16 Dec 2016 11:02:37 +0000 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201612161102.37559.gary.stainburn@ringways.co.uk> X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 106706 [Dec 16 2016] X-KLMS-AntiSpam-Version: 5.7.0.14 X-KLMS-AntiSpam-Envelope-From: gary.stainburn@ringways.co.uk X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Info: LuaCore: 157 157 9c31c0476def61774fb291ea4183b61c3a0839e5, {msgid_created_by_recepient}, 127.0.0.200:5.2.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;eddie.ringways.co.uk:7.1.1;127.0.0.199:7.1.2,5.2.1;ringways.co.uk:7.1.1 X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, 2016/12/15 10:39:48 X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.721, bases: 2016/12/16 04:06:00 #8492275 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Score: -53.9 (---------------------------------------------------) X-Spam-Report: Spam detection software, running on the system "ollie2.ringways.co.uk", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see Gary Stainburn for details. Content preview: I'm creating a simple function that must have been done millions of times before, but I can't get it to work. In this case, I'm checking a user ID and password against previously used passwords: All I want to do is return 'found' based on the select but I can't get it to work. [...] Content analysis details: (-53.9 points, 15.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -50 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.1 SCORE_RCPTS Adding score for each recipient -3.1 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 1.0 RING_SAFE No description available. X-forward-disable: yes X-Pg-Spam-Score: -5.0 (-----) 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 I'm creating a simple function that must have been done millions of times before, but I can't get it to work. In this case, I'm checking a user ID and password against previously used passwords: All I want to do is return 'found' based on the select but I can't get it to work. If I run select 1 from user_previous_passwords where u_id=25 and crypt('MyPaSSword',u_previous_password) = u_previous_password; then it returns the matching row(s) If I run my function create or replace function check_previous_passwords (ID int4, PASS varchar) returns boolean as $$ DECLARE UID int4; BEGIN return exists(select 1 from user_previous_passwords where u_id=ID and crypt(PASS,u_previous_password) = PASS); END; $$ LANGUAGE plpgsql; I always get false; I've tried things like if exist(....) then .... select 1 into UID select count(u_id) into UID update .....set u_id=u_id ...... if found then but I never get the correct result, so I think I must me doing something much more fundamentally wrong. Can someone spot it please? Gary -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql