hi all,
I am having a doubt of how to write a function for my situation.
I am having two tables
[code=text]
portfolioscrip
portfolioscripd etails
[/code]
i have to insert into portfolioscripd etails that table is having a column called portfolioscripi d and portfolioscripd etailsid portfolioscripd etailsid is the auto generated column and portfoliscripid should be insert from portfolioscrip table
[code=sql]
CREATE OR REPLACE FUNCTION insertportfolio (pdate timestamp without time zone)
RETURNS integer AS
$BODY$
declare
id bigint;
countid bigint;
begin
select into countid count(portfolio scripid) from portfolioscrip;
for i in 1....countid loop
select into id portfolioscripi d from portfolioscrip;
insert into portfolioscripd etails (portfolioscrip id,date,bseopen ,bseclose,nseop en,nseclose)val ues(id,pdate,0, 0,0,0);
end loop;
return 1;
END
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION insertportfolio (pdate timestamp without time zone) OWNER TO postgres;
[/code]
this is inserting the date to the same id so many times it is not using next id i have to use like that please help me to solve this problem
thanks in advance
priyan
I am having a doubt of how to write a function for my situation.
I am having two tables
[code=text]
portfolioscrip
portfolioscripd etails
[/code]
i have to insert into portfolioscripd etails that table is having a column called portfolioscripi d and portfolioscripd etailsid portfolioscripd etailsid is the auto generated column and portfoliscripid should be insert from portfolioscrip table
[code=sql]
CREATE OR REPLACE FUNCTION insertportfolio (pdate timestamp without time zone)
RETURNS integer AS
$BODY$
declare
id bigint;
countid bigint;
begin
select into countid count(portfolio scripid) from portfolioscrip;
for i in 1....countid loop
select into id portfolioscripi d from portfolioscrip;
insert into portfolioscripd etails (portfolioscrip id,date,bseopen ,bseclose,nseop en,nseclose)val ues(id,pdate,0, 0,0,0);
end loop;
return 1;
END
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION insertportfolio (pdate timestamp without time zone) OWNER TO postgres;
[/code]
this is inserting the date to the same id so many times it is not using next id i have to use like that please help me to solve this problem
thanks in advance
priyan
Comment