Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cHqo1-0007Zh-8x for pgsql-sql@arkaria.postgresql.org; Fri, 16 Dec 2016 11:36:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cHqo0-0001nh-Qg for pgsql-sql@arkaria.postgresql.org; Fri, 16 Dec 2016 11:36:04 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cHqn3-0000f4-5N for pgsql-sql@postgresql.org; Fri, 16 Dec 2016 11:35:05 +0000 Received: from mr11p26im-asmtp003.me.com ([17.110.86.110]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cHqmw-00005j-D0 for pgsql-sql@postgresql.org; Fri, 16 Dec 2016 11:35:03 +0000 Received: from process-dkim-sign-daemon.mr11p26im-asmtp003.me.com by mr11p26im-asmtp003.me.com (Oracle Communications Messaging Server 7.0.5.38.0 64bit (built Feb 26 2016)) id <0OIA00J00048LK00@mr11p26im-asmtp003.me.com> for pgsql-sql@postgresql.org; Fri, 16 Dec 2016 11:34:53 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=4d515a; t=1481888093; bh=JjxAw/hkpx9if7nN+jgv1itT7hUUXKN0FDNffChOkOU=; h=Content-type:MIME-version:Subject:From:Date:Message-id:To; b=QzVHqyAwgAnLC5lAejXjNATKUgXnpcVHPzMMhjWSeI+va7Q72ISflAXGPdOTJxqmw aU0NA4EgxxF/FYaI12SNhPj3ClpF62SO5onoFNTu7iZCX4gbkEvhZiqo1JC6u/443v 4+8jk2OFulvzNEvT3Bmpg01LvX+FAyzeWaGJmtCXrJrrcn7Pah0jrPcJPkfXBFXfFl 6VMCavcBWH4bdqt50wKIRQswDCs5mroK9HpM4HlhEHyPfyQD7LcNQF/v1lPg64MrQN tGWLKKnkTQoENtTAB/S6MTnJnVgkmURW8mINwC0USDU5wUIYFYTDLelmpIsxhjkTLv oiEuTa2jppiBA== Received: from host49.localnet.jfl (h-213.61.119.251.host.de.colt.net [213.61.119.251]) by mr11p26im-asmtp003.me.com (Oracle Communications Messaging Server 7.0.5.38.0 64bit (built Feb 26 2016)) with ESMTPSA id <0OIA00NE30618730@mr11p26im-asmtp003.me.com>; Fri, 16 Dec 2016 11:34:53 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-12-16_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1034 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1603290000 definitions=main-1612160192 Content-type: text/plain; charset=us-ascii MIME-version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: Re: simple "select / if found" isn't From: Jan Otto In-reply-to: <201612161102.37559.gary.stainburn@ringways.co.uk> Date: Fri, 16 Dec 2016 12:34:48 +0100 Cc: pgsql-sql@postgresql.org Content-transfer-encoding: quoted-printable Message-id: References: <201612161102.37559.gary.stainburn@ringways.co.uk> To: Gary Stainburn X-Mailer: Apple Mail (2.3259) X-Pg-Spam-Score: -5.8 (-----) 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 hi gary, > On 16 Dec 2016, at 12:02, Gary Stainburn = wrote: >=20 > I'm creating a simple function that must have been done millions of times= =20 > before, but I can't get it to work. In this case, I'm checking a user ID= and=20 > password against previously used passwords: >=20 > All I want to do is return 'found' based on the select but I can't get it= to=20 > work.=20=20 >=20 > If I run=20 >=20 > select 1 from user_previous_passwords=20 > where u_id=3D25 and=20 > crypt('MyPaSSword',u_previous_password) =3D u_previous_password; >=20 > then it returns the matching row(s) >=20 > If I run my function >=20 > create or replace function check_previous_passwords (ID int4, PASS varcha= r)=20 > returns boolean as $$ > DECLARE > UID int4; > BEGIN > return exists(select 1 from user_previous_passwords=20 > where u_id=3DID and crypt(PASS,u_previous_password) =3D PASS); return exists(select 1 from user_previous_passwords=20 where u_id=3DID and crypt(PASS,u_previous_password) =3D u_previous_passw= ord); > END; > $$ LANGUAGE plpgsql; regards, jan --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql