By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 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);
Dec 27 '18 #2

Post your reply

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