DanMossa
03/09/2022, 9:17 PMRETURN QUERY SELECT ST_AsEWKT(location) AS location, *
FROM public.users
WHERE user_id = p_user_id
LIMIT 1;
Where p_user_id
is the function param of type uuid
?garyaustin
03/09/2022, 9:48 PMDanMossa
03/09/2022, 9:51 PM[2022-03-09 13:50:58] [42P13] ERROR: return type mismatch in function declared to return users
[2022-03-09 13:50:58] Detail: Final statement returns too many columns.
[2022-03-09 13:50:58] Where: SQL function "get_user"
DanMossa
03/09/2022, 9:51 PMCREATE OR REPLACE FUNCTION get_user(p_user_id uuid) RETURNS SETOF public.users AS
$func$
SELECT *, ST_AsEWKT(location) as location
FROM public.users
WHERE user_id = $1;
$func$ LANGUAGE sql;
DanMossa
03/09/2022, 9:51 PMDanMossa
03/09/2022, 9:52 PMgaryaustin
03/09/2022, 9:53 PMDanMossa
03/09/2022, 9:53 PMgaryaustin
03/09/2022, 9:54 PMDanMossa
03/09/2022, 9:54 PMa column definition list is required for functions returning "record"
garyaustin
03/09/2022, 9:56 PMgaryaustin
03/09/2022, 10:21 PMcreate or replace function test()
returns setof record as $$
select *,'1' from messages;
$$
language sql;
DanMossa
03/09/2022, 10:32 PMDanMossa
03/09/2022, 10:32 PMpostgres: public, extensions> SELECT * FROM test()
[2022-03-09 14:31:51] [42601] ERROR: a column definition list is required for functions returning "record"
[2022-03-09 14:31:51] Position: 15
garyaustin
03/09/2022, 10:59 PMDanMossa
03/09/2022, 11:00 PMgaryaustin
03/09/2022, 11:04 PMgaryaustin
03/09/2022, 11:05 PMDanMossa
03/09/2022, 11:07 PMDanMossa
03/09/2022, 11:08 PMDROP FUNCTION get_user(uuid);
CREATE OR REPLACE FUNCTION get_user(p_user_id uuid)
RETURNS TABLE
(
users_row public.users,
ewkb_location text
)
LANGUAGE plpgsql
AS
$func$
BEGIN
RETURN QUERY
SELECT u, ST_AsEWKT(location) as location
FROM public.users as u
WHERE u.user_id = p_user_id;
END
$func$;
garyaustin
03/09/2022, 11:08 PMDanMossa
03/09/2022, 11:16 PM