why postgres functions returns result in one column? [duplicate]
Asked Answered
M

1

5

I have a simple PostgreSQL function which I aspect should return values into separate columns -115 and 101000005458E6258... but it returns one column where two values are separated by a comma -115,101000005458E6258.... What is wrong with my function?

CREATE OR REPLACE FUNCTION public.get_direction()
RETURNS TABLE(direction integer, geom geometry)             
AS $$
BEGIN
RETURN QUERY SELECT 
    heading-lag(heading) over (order by time) AS direction, a.geom AS geom 
    FROM public.mytable a 
    WHERE reg='125123' 
    GROUP BY heading, a.geom , a.time;
END; $$
LANGUAGE 'plpgsql';

I call the function

SELECT public.get_direction();

Thank you.

Marissamarist answered 25/6, 2020 at 14:7 Comment(3)
And you should call it like this: select * from get_direction();.Barracuda
It is a table function, so it should be used like a table in an SQL statement.Jehoshaphat
Beginner error. Thank you for helpMarissamarist
I
12

If you want the result as a set of columns, then you need:

SELECT * FROM public.get_direction();
Ionosphere answered 25/6, 2020 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.