473,408 Members | 1,775 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,408 software developers and data experts.

ERROR: return type mismatch in function returning tuple

66
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE FUNCTION f_customerlogininfo(varchar, varchar, varchar) RETURNS public.v_customerlogininfo AS '
  2. DECLARE
  3.     p_schm ALIAS FOR $1;
  4.     p_contact ALIAS FOR $2;
  5.     p_status ALIAS FOR $3;
  6.     v_boolstatus boolean;
  7. BEGIN
  8.     IF p_status = ''all'' THEN
  9.         RETURN (select * from v_customerlogininfo where contact = p_contact);
  10.     ELSE
  11.         IF p_status = ''true'' THEN
  12.             v_boolstatus := true;
  13.         ELSIF p_status = ''false'' THEN
  14.             v_boolstatus := false;
  15.         END IF;
  16.             RETURN (select * from v_customerlogininfo where contact = p_contact and status = v_boolstatus);
  17.     END IF;
  18. END; '
  19. LANGUAGE 'plpgsql'
Expand|Select|Wrap|Line Numbers
  1. select f_customerlogininfo ('Iwachi Miura', '09012345678', 'all');
ERROR: return type mismatch in function returning tuple at or near "(";
Aug 13 '07 #1
1 11701
michaelb
534 Expert 512MB
The first problem with your code is that such function must have return type as SETOF TABLE_NAME, not TABLE_NAME
I think the second problem is with your "return (select ...)" code.
plpgsql function would typically do something like this:
Expand|Select|Wrap|Line Numbers
  1. create or replace function getSetOf (int, int) returns setof tab_name as
  2. '
  3.  declare
  4.     -- either one will do
  5.     ret_row record;
  6.     -- ret_row tab_name%rowtype;
  7.     start_id alias for $1;
  8.     end_id   alias for $2;
  9.  
  10.   begin
  11.      FOR ret_row in select * from tab_name 
  12.              where tab_name.id between start_id and end_id LOOP
  13.         return next ret_row;
  14.      END LOOP;
  15.  
  16.   return;
  17.   end;
  18. '
  19. language 'plpgsql';
  20.  
Review these docs for more information:
http://www.postgresql.org/docs/8.1/s...efunction.html
http://www.postgresql.org/docs/8.1/s...tructures.html
http://www.postgresql.org/docs/8.1/s...larations.html
http://www.postgresql.org/docs/8.1/s...xfunc-sql.html
Aug 14 '07 #2

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

Similar topics

1
by: Jon Perez | last post by:
I want to retrieve a value from a tuple and convert it to a C type. Is the following idiom okay? if (!( ( tmp_pyobj=PyTuple_GetItem(tuple,1) ) && ( c_int=PyInt_AsLong(tmp_pyobj) ) )) { if...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
5
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
4
by: leslie_tighe | last post by:
Hello, I have a method on a com+ object that is returning an array of objects. I know the array is popluated as calls to check the ubound and lbound show valid values. However, any calls to...
10
by: ale.of.ginger | last post by:
Greetings! I am trying to make a multiplayer (no AI, 2 person) game of tic tac toe in Python. So far it has been pretty simple. My only concern is with the win checking to see if a person has...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
3
by: Oliver Bleckmann | last post by:
hey, which ways are available i c++ to return multiple values i know u can use structs, any other methods? concrete question: i want to do sth. like this: returning two strings into stringvars...
9
by: Jim | last post by:
Hello, I'm trying to write exception-handling code that is OK in the presence of unicode error messages. I seem to have gotten all mixed up and I'd appreciate any un-mixing that anyone can...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.