424,051 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,051 IT Pros & Developers. It's quick & easy.

Can I RETURN SET OF typeX or typeY in a function depending of a parameter ?

P: 1
That I want to ask is if I can return type A or B in the function depending of a parameter. For example



CREATE or replace FUNCTION public.getDataFromSearch(
searchString VARCHAR,
typeOperation INTEGER)
RETURNS SETOF typeA OR typeB AS ...

If typeOperation is 'A' can I return a query with the structure or typeA and if is 'B' the second type ?
Oct 23 '18 #1
Share this Question
Share on Google+
1 Reply


P: 3
Use Record as function output type


FUNCTION public.getDataFromSearch(
searchString VARCHAR,
typeOperation INTEGER)
RETURNS SETOF record


If you call the function, you know which type will return

Select * from FUNCTION public.getDataFromSearch('text',1) as (RETURN_field bigint);
Select * from FUNCTION public.getDataFromSearch('text',2) as (RETURN_field varchar);
3 Weeks Ago #2

Post your reply

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