pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Calling Postgresql Function to delete user data
2+ messages / 2 participants
[nested] [flat]

* Calling Postgresql Function to delete user data
@ 2012-02-11 19:53 Rehan Saleem <pk_rehan@yahoo.com>
  2012-02-12 13:02 ` Re: Calling Postgresql Function to delete user data Philip Couling <phil@pedal.me.uk>
  0 siblings, 1 reply; 2+ messages in thread

From: Rehan Saleem @ 2012-02-11 19:53 UTC (permalink / raw)
  To: pgsql-sql

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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Calling Postgresql Function to delete user data
  2012-02-11 19:53 Calling Postgresql Function to delete user data Rehan Saleem <pk_rehan@yahoo.com>
@ 2012-02-12 13:02 ` Philip Couling <phil@pedal.me.uk>
  0 siblings, 0 replies; 2+ messages in thread

From: Philip Couling @ 2012-02-12 13:02 UTC (permalink / raw)
  To: pgsql-sql

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.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2012-02-12 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-02-11 19:53 Calling Postgresql Function to delete user data Rehan Saleem <pk_rehan@yahoo.com>
2012-02-12 13:02 ` Philip Couling <phil@pedal.me.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox