473,385 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

doubt in function

priyan
54
hi all,
I am having a doubt of how to write a function for my situation.

I am having two tables
Expand|Select|Wrap|Line Numbers
  1. portfolioscrip
  2. portfolioscripdetails
  3.  
i have to insert into portfolioscripdetails that table is having a column called portfolioscripid and portfolioscripdetailsid portfolioscripdetailsid is the auto generated column and portfoliscripid should be insert from portfolioscrip table
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION insertportfolio(pdate timestamp without time zone)
  2.   RETURNS integer AS
  3. $BODY$
  4. declare
  5. id bigint;
  6. countid bigint;
  7. begin
  8. select into countid count(portfolioscripid) from portfolioscrip;
  9. for i in 1....countid loop
  10. select into id portfolioscripid from portfolioscrip;
  11. insert into portfolioscripdetails (portfolioscripid,date,bseopen,bseclose,nseopen,nseclose)values(id,pdate,0,0,0,0);
  12. end loop;
  13. return 1;
  14. END
  15. $BODY$
  16.   LANGUAGE 'plpgsql' VOLATILE;
  17. ALTER FUNCTION insertportfolio(pdate timestamp without time zone) OWNER TO postgres;
  18.  

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
Sep 11 '07 #1
2 2520
amitpatel66
2,367 Expert 2GB
hi all,
I am having a doubt of how to write a function for my situation.

I am having two tables
Expand|Select|Wrap|Line Numbers
  1. portfolioscrip
  2. portfolioscripdetails
  3.  
i have to insert into portfolioscripdetails that table is having a column called portfolioscripid and portfolioscripdetailsid portfolioscripdetailsid is the auto generated column and portfoliscripid should be insert from portfolioscrip table
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION insertportfolio(pdate timestamp without time zone)
  2.   RETURNS integer AS
  3. $BODY$
  4. declare
  5. id bigint;
  6. countid bigint;
  7. begin
  8. select into countid count(portfolioscripid) from portfolioscrip;
  9. for i in 1....countid loop
  10. select into id portfolioscripid from portfolioscrip;
  11. insert into portfolioscripdetails (portfolioscripid,date,bseopen,bseclose,nseopen,nseclose)values(id,pdate,0,0,0,0);
  12. end loop;
  13. return 1;
  14. END
  15. $BODY$
  16.   LANGUAGE 'plpgsql' VOLATILE;
  17. ALTER FUNCTION insertportfolio(pdate timestamp without time zone) OWNER TO postgres;
  18.  

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
Why you need to write a function here?? rather you can achieve this with a single insert statement:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO portfolioscripdetails (portfolioscripid,date,bseopen,bseclose,nseopen,ns  eclose)
  2. (SELECT portfolioscripid,<substitute your pdate here>,0,0,0,0);
  3.  
The above insert will insert all the portfolioscripid from one table to another......
Sep 11 '07 #2
priyan
54
Why you need to write a function here?? rather you can achieve this with a single insert statement:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO portfolioscripdetails (portfolioscripid,date,bseopen,bseclose,nseopen,ns  eclose)
  2. (SELECT portfolioscripid,<substitute your pdate here>,0,0,0,0);
  3.  
The above insert will insert all the portfolioscripid from one table to another......

Thanks amitpatel i got the answer thanks a lot........
Sep 11 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: SK | last post by:
Hi all, I have a doubt in C++ Templates by Nicolai M. Josuttis. On Page 17 there is a line "In general, it is a good idea not to change more than necessary when overloading function templates....
3
by: Old Monk | last post by:
Hi all, I have got a doubt in Koenig& Moo's AC++. On page 228 and 230, authors provide definitions for Core and Grad classes. Grad IS-A Core, i.e. public inheritance. What puzzles me is that...
1
by: Mohamed Fysal | last post by:
Hi , I have written a Regular DLL and derived the App class from CNDKClient class so that this DLL is used by another EXE to act as a Client to a Server Application which I developed deriving...
1
by: Srini | last post by:
I was reading the "Exceptional C++" of Herb Sutter. In an example, he mentions the following. // In some library header: namespace N { class C{}; } int operator+(int i, N::C) { return i+1; }...
5
by: Srini | last post by:
Hello all, I was going thru the GotW archives where I had a doubt in this particular item. http://www.gotw.ca/gotw/027.htm There is a mention about a subtle change to the standard in July...
38
by: edu.mvk | last post by:
Hi I am using strcpy() in my code for copying a string to another string. i am using static char arrays. for the first time it is exected correctly but the second time the control reaches...
8
by: toton | last post by:
HI, One more small doubt from today's mail. I have certain function which returns a pointer (sometimes a const pointer from a const member function). And certain member function needs reference...
4
by: sureshk | last post by:
In 'C' the signature of any function's prototype and the definiton of the function should match.But for function main may recieve the arguments or may not recieve the arguments 'It is optional'. How...
13
by: deepak | last post by:
Hi In the following function how the memory 'll be allocated. 1) Will it allocate memory for all the char's together or allocate for first char. then for int then for float and after this only...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.