Thread

  1. About SP's and parameters

    Alfonso Peniche <alfonso@iteso.mx> — 2001-02-08T22:40:27Z

    Hi all:
    
        Is there a way to pass a tablename as a parameter to a SP?
    
        I'll try to explain myself. I want to create a SP that can, for
    instance, do a delete from ...... so that any particular application all
    
    it has to do is call the SP sending the table to be deleted.
    
        Right now I have:
    
    CREATE FUNCTION deleteanytable (bpchar)
    returns integer
    as '
        begin
            delete from $1;
    
            return 1;
        end;'
    language 'plpgsql';
    
    If I call it:
        select deleteanytable ( mytable );
    
    I get a message saying
    
    ERROR:  Attribute 'mytable' not found
    
    Thanks for your help.
    
    P.S. It would be very interesting if a columnname could also be sent as
    a parameter to the Stored Procedure.
    
    
    
    
    
  2. Re: About SP's and parameters

    alex@pilosoft.com — 2001-02-08T23:10:56Z

    in 7.1, there's "EXECUTE" command in plsql, so you can do:
    
    execute 'delete from ' || $1;
    
    -alex
    
    On Thu, 8 Feb 2001, Alfonso Peniche wrote:
    
    > Hi all:
    > 
    >     Is there a way to pass a tablename as a parameter to a SP?
    > 
    >     I'll try to explain myself. I want to create a SP that can, for
    > instance, do a delete from ...... so that any particular application all
    > 
    > it has to do is call the SP sending the table to be deleted.
    > 
    >     Right now I have:
    > 
    > CREATE FUNCTION deleteanytable (bpchar)
    > returns integer
    > as '
    >     begin
    >         delete from $1;
    > 
    >         return 1;
    >     end;'
    > language 'plpgsql';
    > 
    > If I call it:
    >     select deleteanytable ( mytable );
    > 
    > I get a message saying
    > 
    > ERROR:  Attribute 'mytable' not found
    > 
    > Thanks for your help.
    > 
    > P.S. It would be very interesting if a columnname could also be sent as
    > a parameter to the Stored Procedure.
    > 
    > 
    > 
    > 
    
    
    
  3. Re: About SP's and parameters

    Alfonso Peniche <alfonso@iteso.mx> — 2001-02-09T01:03:18Z

    And where can I find information about EXECUTE and other new
    features/instructions (I haven't found anything in the online manual)?
    
    Alex Pilosov wrote:
    
    > in 7.1, there's "EXECUTE" command in plsql, so you can do:
    >
    > execute 'delete from ' || $1;
    >
    > -alex
    >
    > On Thu, 8 Feb 2001, Alfonso Peniche wrote:
    >
    > > Hi all:
    > >
    > >     Is there a way to pass a tablename as a parameter to a SP?
    > >
    > >     I'll try to explain myself. I want to create a SP that can, for
    > > instance, do a delete from ...... so that any particular application all
    > >
    > > it has to do is call the SP sending the table to be deleted.
    > >
    > >     Right now I have:
    > >
    > > CREATE FUNCTION deleteanytable (bpchar)
    > > returns integer
    > > as '
    > >     begin
    > >         delete from $1;
    > >
    > >         return 1;
    > >     end;'
    > > language 'plpgsql';
    > >
    > > If I call it:
    > >     select deleteanytable ( mytable );
    > >
    > > I get a message saying
    > >
    > > ERROR:  Attribute 'mytable' not found
    > >
    > > Thanks for your help.
    > >
    > > P.S. It would be very interesting if a columnname could also be sent as
    > > a parameter to the Stored Procedure.
    > >
    > >
    > >
    > >