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. -
DECLARE
-
dcursor CURSOR (tdate date) IS SELECT * FROM recon.sp_ubsdaily_asof(tdate) AS u WHERE u.maturity_date >= tdate AND u.qty <> 0
-
AND NOT EXISTS(SELECT 1 FROM recon.ubs_daily_portfolio AS p WHERE u.serial_number = p.serial_number);
-
udaily recon.ubsdaily%ROWTYPE;
-
umark recon.ubsmark%ROWTYPE;
-
ubscount bigint;
-
-
BEGIN
-
SELECT COUNT(*) INTO ubscount FROM recon.ubs_daily_portfolio;
-
-
IF ubscount = 0 THEN
-
EXIT;
-
END IF;
-
-
OPEN dcursor(asof);
-
-
LOOP
-
FETCH dcursor INTO udaily;
-
EXIT WHEN NOT FOUND;
-
-
IF (udaily.modified_date <> asof) THEN
-
INSERT INTO recon.ubsdaily (serial_number, modified_date, trade_date, maturity_date, deal_price, strike, trade_type, market,
-
product_code, product_name, acct_number, qty, ccy_code, strategy, tp_id, arcim_id)
-
VALUES(udaily.serial_number, asof, udaily.trade_date, udaily.maturity_date, udaily.deal_price, udaily.strike,
-
udaily.trade_type, udaily.market, udaily.product_code, udaily.product_name, udaily.acct_number, 0, udaily.ccy_code,
-
udaily.strategy, udaily.tp_id, udaily.arcim_id);
-
ELSE
-
UPDATE recon.ubsdaily SET qty = 0 WHERE id = udaily.id;
-
END IF;
-
-
SELECT m.* INTO umark FROM recon.ubsmark AS m WHERE m.serial_number = udaily.serial_number
-
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);
-
-
IF NOT FOUND THEN
-
INSERT INTO recon.ubsmark (serial_number, mark_date, mark, implied_pnl, variation_margin, premium_value, realized_pnl)
-
VALUES(udaily.serial_number, asof, 0, 0, 0, 0, 0);
-
ELSE
-
-
IF (umark.mark_date = asof) THEN
-
UPDATE recon.ubsmark set implied_pnl = 0, variation_margin = 0, premium_value = 0, realized_pnl = umark.implied_pnl
-
WHERE id = umark.id;
-
ELSE
-
INSERT INTO recon.ubsmark (serial_number, mark_date, mark, implied_pnl, variation_margin, premium_value, realized_pnl)
-
VALUES(udaily.serial_number, asof, 0, 0, 0, 0, umark.realized_pnl);
-
END IF;
-
-
END IF;
-
-
END LOOP;
-
-
CLOSE dcursor;
-
END;
-
1 1622
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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):
|
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...
|
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
|
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...
| |
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...
|
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...
|
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...
|
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
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |