473,598 Members | 3,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

table functions + user defined types

Ladies and Gentlemen,

Please, enlighten me, if you can, in the following matter:

I made a type:

create type my_type as (
a integer,
b integer
);

since I have a table:

create table my_table (
a integer;
);

and I have now a function too:

create or replace function my_func (
integer, -- a
integer, -- b
) returns setof my_type as
'
declare
pa alias for $1;
pb alias for $2;
-- declarations
my_value my_type;
begin
my_value.a := pa;
my_value.b := pb;
return my_value;
end;
' language 'plpgsql';

when I run this darling function I get a parse error pointing to the line after "begin".

What am I doing wrong? I have skimmed through all the manuals, had a look at the postgresql cookbook, no info on this. I just would like to have a function that returns more fields at the same time - add a column to table my_table, where I could occasionally return some value (e.g. error code). Howto do this?

Thanks for your advice in advance

Zoltan Bartko
Nov 12 '05 #1
1 1807
On 27/10/03 3:20 pm, "BARTKO, Zoltan" <ba***********@ pobox.sk> wrote:
Ladies and Gentlemen,

Please, enlighten me, if you can, in the following matter:

I made a type:

create type my_type as (
a integer,
b integer
);

since I have a table:

create table my_table (
a integer;
);

and I have now a function too:

create or replace function my_func (
integer, -- a
integer, -- b
) returns setof my_type as
'
declare
pa alias for $1;
pb alias for $2;
-- declarations
my_value my_type;
begin
my_value.a := pa;
my_value.b := pb;
return my_value;
end;
' language 'plpgsql';

Try this....

create or replace function my_func (
integer, -- a
integer -- b
) returns my_type as
'
declare
pa alias for $1;
pb alias for $2;
-- declarations
my_value record;
begin
select into my_value pa, pb;
return my_value;
end;
' language 'plpgsql';

when I run this darling function I get a parse error pointing to the line
after "begin".

What am I doing wrong? I have skimmed through all the manuals, had a look at
the postgresql cookbook, no info on this. I just would like to have a
function that returns more fields at the same time - add a column to table
my_table, where I could occasionally return some value (e.g. error code). How
to do this?

Thanks for your advice in advance

Zoltan Bartko


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #2

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

Similar topics

0
2338
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and Methods Version: $Revision: 1.34 $ Last-Modified: $Date: 2004/09/03 09:32:50 $ Author: Kevin D. Smith, Jim Jewett, Skip Montanaro, Anthony Baxter
61
24443
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will 'stretch'</td> <td valign="top" width="300">some data that won't 'stetch'</td> </tr> </table>
2
3774
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short- cut solution for finding collisions in SHA-1 . Their result
19
4237
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
44
2400
by: bahadir.balban | last post by:
Hi, What's the best way to implement an overloaded function in C? For instance if you want to have generic print function for various structures, my implementation would be with a case statement: void print_structs(void * struct_argument, enum struct_type stype) { switch(stype) { case STRUCT_TYPE_1:
5
2310
by: Bern McCarty | last post by:
I have a DLL written in C++ (it's really C code that was adjusted to compile OK as C++) that I compile successfully into IL with the /CLR switch of Visual C 7.1. I use the resultant library successfully from other C++ code (both native and managed) and it works fine. I would like to figure out the shortest and most convenient path to making this library callable from other ..NET languages. The function signatures in this librariy's API are...
8
2307
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR types. The problem: I have a number of mixed-mode functions which I want reuse. These functions revolve around converting a CLR String to a C++ std::string or
31
1765
by: Michael | last post by:
Why are functions atomic? (I.e. they are not copied.) For example, I would like to make a copy of a function so I can change the default values: (2, 2) I would like the following behaviour: (1,2)
6
1819
by: LSW | last post by:
I've tried googling for the answer to this one, but haven't found anything. In the following code snippet BOOLEAN SomeValue; if(SomeValue && SomeFunc()) DoSomething; If SomeValue is False, will SomeFunc() be evaluated? Or will the evaluation stop when a False is encountered in a boolean AND expression?
12
9113
by: Michael.Z | last post by:
Anyone who can help: Given a Table.h file I am writing a Table.c file. I keep getting the compile error: previous declaration of Table was here / conflicting types for I think the problem was the result of two pieces of code. First: typedef struct Table; /* in Table.c*/
0
7902
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
8398
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
8265
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6719
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...
1
5850
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
5438
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
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
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.