Обсуждение: View and function

Поиск
Список
Период
Сортировка

View and function

От
DaVinci
Дата:
 Hello.

 I am trying to insert a tupla in a view with rules for inserting from a
 function. This is my data:

-----------------------------------------------------------------------
create table dirección (
    cod     serial primary key,
    calle       text,
    vía         int2    references vía(cod),
    localidad   int4    references localidad(cod),
    provincia   int4    references provincia(cod)
);
create index dir_calle_ndx on dirección (calle);
create index dir_via_ndx on dirección (vía);
create index dir_localidad_ndx on dirección (localidad);
create index dir_provincia_ndx on dirección (provincia);

create view v_dirección as
    select * from dirección
;

create rule v_dirección_ins as on insert to v_dirección do instead
    (insert into dirección(calle,vía,localidad,provincia) values (
        NEW.calle,
        NEW.vía,
        NEW.localidad,
        NEW.provincia);
        select currval('dirección_cod_seq'))
;

create function pilpot(calle) returns integer as '
declare
    c alias for $1;
    n integer;
begin
    insert into v_dirección(calle) values (c);
    get diagnostics n = result_oid;
    return n;
end;
' language 'plpgsql';

------------------------------------------------------------------

 I get an error when creating function of type:

     ERROR:  ProcedureCreate: arg type 'calle' is not defined

 but when I try that insert from psql prompt, all works well.

 Where is my mental bug? :)

 Thanks.

                                                 David

Re: View and function

От
"Thomas F. O'Connell"
Дата:
DaVinci wrote:


> create function pilpot(calle) returns integer as '

this is your problem. try this:

create function pilpot(text) returns integer as '

the syntax for creating postgres functions is to declare the types, not
the identifiers of any parameters.

-tfo




Re: View and function

От
Stephan Szabo
Дата:
> create function pilpot(calle) returns integer as '
> declare
>     c alias for $1;
>     n integer;
> begin
>     insert into v_direcci�n(calle) values (c);
>     get diagnostics n = result_oid;
>     return n;
> end;
> ' language 'plpgsql';
>
> ------------------------------------------------------------------
>
>  I get an error when creating function of type:
>
>      ERROR:  ProcedureCreate: arg type 'calle' is not defined

calle is a field name right?  It's probably complaining at
pilpot(calle) since calle in that case is supposed to be a
type name.