0

I am trying to fetch data from remote DB by using select tester01() through function but getting an error "query has no destination for result data". I am using plpgsql language to do the same.

'''

CREATE OR REPLACE FUNCTION public.tester01()
RETURNS text
LANGUAGE plpgsql
AS $function$
DECLARE
students text;
BEGIN
students:='success';
 select 'werewwer';
select * from test_data where t_first_name='Shahbaz@gmail.com';

RETURN students;

END;
$function$
;

'''

''' Calling Function:

 select tester01()

''' ''' Error:

query has no destination for result data '''

Shahbaz Khan
  • 1
  • 1
  • 1
  • https://stackoverflow.com/questions/69135394/hasura-query-has-no-destination-for-result-data – Alex Yu Sep 14 '21 at 17:44
  • 1
    Does this answer your question? [Hasura - query has no destination for result data](https://stackoverflow.com/questions/69135394/hasura-query-has-no-destination-for-result-data) – Alex Yu Sep 14 '21 at 17:46

1 Answers1

1

The error message clearly says what the problem is. You're running a SELECT inside the function, but never put the results of the query into any variable.

select 'werewwer'; would love to return one row of data, but where to?

The correct syntax would be like this

CREATE OR REPLACE FUNCTION public.tester01()
RETURNS text
LANGUAGE plpgsql
AS $function$
DECLARE
students text;
BEGIN
--students := 'success';
--students := (select 'something else');
students := (select * from test_data where t_first_name='Shahbaz@gmail.com');

RETURN students;

END;
$function$
;
Megadest
  • 614
  • 4
  • 15