473,786 Members | 2,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

casting parameters to a function

I am trying to move all of the sql statements from my code into a pl/pgsql
function. I have one function for a transaction block that contains 10
inserts and I need to pass 50 parameters to it.

Well I can't do that, so I was playing around with passing the parameters in
as a varchar[] array, but then I have the issue of the variables being the
wrong type when I insert them.

I was playing around with trying to convert types, but it isn't working so
far. The function takes a single varchar[] as an argument..

This doesn't work:
s ALIAS FOR $1;
in_trans_date timestamp := s[3];

and this doesn't work either:
in_trans_date timestamp := $1[3];

Can someone help me in how to assign an array element to a variable and cast
it?
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 22 '05 #1
2 1843

I finally figured out that you cannot assign parameters to a variable in the
DECLARE section, it has to be done inside the BEGIN/END block. except for
the ALIAS command it seems that parameters do not exist in the DECLARE
block.

I am trying to move all of the sql statements from my code into a pl/pgsql
function. I have one function for a transaction block that contains 10
inserts and I need to pass 50 parameters to it.

Well I can't do that, so I was playing around with passing the parameters in as a varchar[] array, but then I have the issue of the variables being the
wrong type when I insert them.

I was playing around with trying to convert types, but it isn't working so
far. The function takes a single varchar[] as an argument..

This doesn't work:
s ALIAS FOR $1;
in_trans_date timestamp := s[3];

and this doesn't work either:
in_trans_date timestamp := $1[3];

Can someone help me in how to assign an array element to a variable and cast it?
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 22 '05 #2
"Chris Ochs" <ch***@paymento nline.com> writes:
I was playing around with trying to convert types, but it isn't working so
far. The function takes a single varchar[] as an argument.. This doesn't work:
s ALIAS FOR $1;
in_trans_date timestamp := s[3]; and this doesn't work either:
in_trans_date timestamp := $1[3];


These should work, and do work in CVS tip, but in 7.4 and before you'll
need to do the assignment separately from the variable declaration, eg

DECLARE
s ALIAS FOR $1;
in_trans_date timestamp;
BEGIN
in_trans_date := s[3];
...

PITA, I know, but the previous coding didn't allow any variable
references in initialization expressions. If it really bugs you
you could drop the CVS-tip version of src/pl/plpgsql/src/gram.y
into 7.4 to get the fix:

2003-12-22 19:01 tgl

* src/pl/plpgsql/src/gram.y: Allow plpgsql variables' default value
expressions to reference existing variables (such as function
parameters). Per gripe from David Fetter.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
1935
by: JustSomeGuy | last post by:
I have two object types ClassA and ClassB class ClassA { public: int data; operator ClassB() { ClassB b; b.data = data + 1; return (b);
5
1918
by: el prinCipante | last post by:
I'm getting tired of the following error message. Compiler Error message : Error: Need explicit cast to convert from: float to: float * I am trying to use a routine from the Numerical Recipes library called amebsa.c. The routine requires several parameters of the following form. *iter, **p, *yb.... . How does one initialize these variables? If I declare them as pointer (in this case, *yb and *iter) the compiler still tells me that it...
33
2290
by: hermit_crab67 | last post by:
Can someone explain to a C newbie why this doesn't work as I expect it to work? (expectations clearly outlined in the printf statement in main routine) OS: Linux 2.4.26 GCC: 2.95.4 void modify_pointer(char *); int main(int argc, char *argv) {
7
2141
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
6
2526
by: crook | last post by:
I have code below and it works properly but when I'm compiling it with "--pedantic" flag, GCC(3.4.2) shows such warning: "ISO C forbids casting nonscalar to the same type". How can I change this code to get rid of this warning? /*parameters is void* type*/ struct params p = ( struct params )*( ( struct params * )parameters );
3
3657
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
13
3045
by: DaTurk | last post by:
Hi, This is a question brought about by a solution I came up with to another question I had, which was "Dynamic object creation". So, I'm curious if you can dynamically cast an object. If you have two object which have a common base class, they can both be cast up to the base class, but if either of the child classes have unuque methods you will not be able to access them. Now I know about late binding and all that stuff, but I need...
10
1496
by: active | last post by:
Function CastIt (byval z as boolean) As ?? if z then CastIt = DirectCast(ActiveMdiChild, MyForm1) else CastIt = DirectCast(ActiveMdiChild, MyForm2) end if End Function Can I make a function in VB that returns the result of a DirectCast.
5
3109
by: Gene | last post by:
Hello all. Is the initializing assignment below ANSI standard- conforming? Is there a way to have the prefix parameters to ... type checked in such an assignment? E.g. in this case int x in the typedef matched with int a of foo? Appreciate the help. ------------
0
9650
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
9497
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
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...
1
7515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6748
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
5398
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...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.