Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 11ECC15095CB for ; Sun, 12 Feb 2012 09:02:43 -0400 (AST) Received: from mail-we0-f174.google.com ([74.125.82.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RwZ4j-0004wa-5M for pgsql-sql@postgresql.org; Sun, 12 Feb 2012 13:02:42 +0000 Received: by werb13 with SMTP id b13so2942988wer.19 for ; Sun, 12 Feb 2012 05:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=vz5uK9+c4d+quMfvWffTn6kI+kReYGXoi8Hqee1ZlIw=; b=vADwBrxHltqzjConrZl7hun0vTMspa3PiLov8zztXO4XbtUu1gkW99QcSts0OOXET4 zN2ELGVrdmGOsxoPZgAxsgVN/7PZXS8UIt0uuY8/LGkdRS7wZ08V6gbSbuQhCKs7OslP j6vGe6FPI8sejqoNC7G50N5BqYDESdeuvwtTQ= Received: by 10.216.131.6 with SMTP id l6mr4829286wei.45.1329051747992; Sun, 12 Feb 2012 05:02:27 -0800 (PST) Received: from zbox.pedal.me.uk (cpc2-king5-0-0-cust1226.perr.cable.virginmedia.com. [82.36.220.203]) by mx.google.com with ESMTPS id eq5sm36821452wib.2.2012.02.12.05.02.26 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 12 Feb 2012 05:02:27 -0800 (PST) Received: from [192.168.10.22] (unknown [82.36.220.203]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by zbox.pedal.me.uk (Postfix) with ESMTPSA id 3730A1980437 for ; Sun, 12 Feb 2012 13:02:29 +0000 (GMT) Message-ID: <4F37B85C.70000@pedal.me.uk> Date: Sun, 12 Feb 2012 13:02:20 +0000 From: Philip Couling User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Calling Postgresql Function to delete user data References: <1328990017.24868.YahooMailNeo@web121603.mail.ne1.yahoo.com> In-Reply-To: <1328990017.24868.YahooMailNeo@web121603.mail.ne1.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201202/39 X-Sequence-Number: 36332 On 11/02/2012 19:53, Rehan Saleem wrote: > Hi , > I have created this function to remove UserDataAccountid > from both tables > UserAccountDetails and UserAC > CREATE OR REPLACE FUNCTION DeleteUserData(ACDetailsID int[]) > RETURNS void AS $$ > DECLARE _id int; > BEGIN > -- postgresql has no table type, use a int array instead > FOR _id IN array_lower(ACDetailsID,1) .. array_upper(ACDetailsID,1) > LOOP > DELETE FROM UserAccountDetails WHERE UserDataAcountId= > _id; > DELETE FROM UserAC WHERE UserDataAcountId= _id; > END; > END LOOP; > EXCEPTION WHEN OTHERS THEN > RAISE WARNING 'some issue %', SQLERRM; > END; > $$ LANGUAGE plpgsql; > > Now I am calling this function to delete userdataacountid > from both tables, say i have a user with userdataacountid '5', how can i delete > this user by calling this function , i have tried > > select DeleteUserData(5); > and > select * from DeleteUserData(5); > > its not working , > thanks I would guess that the error you're getting is: ERROR: function deleteuserdata(integer) does not exist LINE 1: select DeleteUserData(5); ^ This is happening because your function takes an array, not a single integer. PostgreSQL can automatically cast from a string to an array if the string is properly formatted: select DeleteUserData('{5}'); Hope this helps.