473,765 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nested use of found doesn't seem to be working

1 New Member
I have a simple plpgsql function that loops using a cursor and performs inserts/updates on a couple of tables. When I run the SQL piecemeal in pgAdmin's SQL editor everything looks OK. However, the IF statement that uses FOUND within the loop seems to always false. Any constructive insights would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.    dcursor CURSOR (tdate date) IS SELECT * FROM recon.sp_ubsdaily_asof(tdate) AS u WHERE u.maturity_date >= tdate AND u.qty <> 0
  3.       AND NOT EXISTS(SELECT 1 FROM recon.ubs_daily_portfolio AS p WHERE u.serial_number = p.serial_number);
  4.    udaily recon.ubsdaily%ROWTYPE; 
  5.    umark recon.ubsmark%ROWTYPE;
  6.    ubscount bigint;
  7.  
  8. BEGIN
  9.    SELECT COUNT(*) INTO ubscount FROM recon.ubs_daily_portfolio;
  10.  
  11.    IF ubscount = 0 THEN
  12.       EXIT;
  13.    END IF;
  14.  
  15.    OPEN dcursor(asof);
  16.  
  17.    LOOP
  18.       FETCH dcursor INTO udaily;
  19.       EXIT WHEN NOT FOUND;
  20.  
  21.       IF (udaily.modified_date <> asof) THEN
  22.          INSERT INTO recon.ubsdaily (serial_number, modified_date, trade_date, maturity_date, deal_price, strike, trade_type, market,
  23.             product_code, product_name, acct_number, qty, ccy_code, strategy, tp_id, arcim_id)
  24.             VALUES(udaily.serial_number, asof, udaily.trade_date, udaily.maturity_date, udaily.deal_price, udaily.strike, 
  25.             udaily.trade_type, udaily.market, udaily.product_code, udaily.product_name, udaily.acct_number, 0, udaily.ccy_code, 
  26.             udaily.strategy, udaily.tp_id, udaily.arcim_id);
  27.       ELSE 
  28.          UPDATE recon.ubsdaily SET qty = 0 WHERE id = udaily.id;
  29.       END IF;
  30.  
  31.       SELECT m.* INTO umark FROM recon.ubsmark AS m WHERE m.serial_number = udaily.serial_number 
  32.          AND m.mark_date = (SELECT MAX(mm.mark_date) FROM recon.ubsmark AS mm WHERE mm.serial_number = udaily.serial_number AND mm.mark_date <= asof);
  33.  
  34.       IF NOT FOUND THEN
  35.          INSERT INTO recon.ubsmark (serial_number, mark_date, mark, implied_pnl, variation_margin, premium_value, realized_pnl) 
  36.             VALUES(udaily.serial_number, asof, 0, 0, 0, 0, 0);
  37.       ELSE 
  38.  
  39.          IF (umark.mark_date = asof) THEN
  40.             UPDATE recon.ubsmark set implied_pnl = 0, variation_margin = 0, premium_value = 0, realized_pnl = umark.implied_pnl 
  41.                WHERE id = umark.id;
  42.          ELSE
  43.             INSERT INTO recon.ubsmark (serial_number, mark_date, mark, implied_pnl, variation_margin, premium_value, realized_pnl) 
  44.                VALUES(udaily.serial_number, asof, 0, 0, 0, 0, umark.realized_pnl);
  45.          END IF;
  46.  
  47.       END IF;
  48.  
  49.    END LOOP;
  50.  
  51.    CLOSE dcursor;
  52. END;
  53.  
Feb 16 '07 #1
1 1622
jshanab
1 New Member
Speculation here,
The Manual says that FOUND is a local variable initially set to False in PLPGsql functions. Maybe you can't access it inside the nested instance. Perhaps wrapping the nested part in a begin-end block of it's own will get you an instance
Apr 3 '07 #2

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

Similar topics

6
2569
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote: (http://www.python.org/search/hypermail/python-1993/0343.html) "This is because nested function definitions don't have access to the local variables of the surrounding block -- only to the globals of the
9
2161
by: OKB (not okblacke) | last post by:
For a variety of reasons, I'm interested in putting together some code that will allow me to created structures out of nested classes, something like: class class1: def methA(self): print "Some code here" class class2: propA = "A" def methB(self):
3
6472
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
8
16919
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. This works fine if all of the properties are at the top (root level) of the model but I'd like to keep them in nested classes to organize them better. So, for example, part of my data model looks like this (simplified) : public class MainClass
0
2208
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child gridview I have set an ItemStyle property of width 20% for the first templated field which contains a hyperlink control, and an ItemStyle of width 80% for the second templated field which contains a label. Both of these controls are databound to...
78
4972
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only problem is that my little helper function doesn't work! It claims that a variable doesn't exist. If I move the variable declaration, it finds the variable, but can't change it. Declaring the variable global in the nested function doesn't work...
1
16757
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
2
2830
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
4
1888
by: henry | last post by:
Folks: Using Dreamweaver CS3... Consider a home page, "index.php" which conditionally REQUIREs one of 'N' HTML files of pure content. All site styles are specified in a master CSS file, "siteformatting.css" The home page, "index.php" must link to the master CSS file, so that HTML elements in this file can conform to site-wide standards, right? (Or
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.