Answer the question
In order to leave comments, you need to log in
How to return data from a function as a table?
There is such a function:
CREATE OR REPLACE FUNCTION "public"."GetAllNotes"("long" float8, "lat" float8)
RETURNS TABLE("userid" int4, "username" varchar, "notename" varchar, "notelong" float8, "notelat" float8) AS $BODY$
DECLARE
BEGIN
RETURN query (SELECT notes."userid", users."name", notes."name", notes."longitude", notes."latitude" FROM notes INNER JOIN users ON notes."userid" = users."id" WHERE (point(long, lat) <@> point(notes."longitude", notes."latitude") <= 0.124274) );
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000
CREATE TABLE "public"."notes" (
"id" int4 NOT NULL DEFAULT nextval('notes_id_seq'::regclass),
"userid" int4 NOT NULL,
"name" varchar COLLATE "pg_catalog"."default" NOT NULL,
"longitude" float8 NOT NULL,
"latitude" float8 NOT NULL,
CONSTRAINT "notes_pkey" PRIMARY KEY ("id")
)
;
ALTER TABLE "public"."notes"
OWNER TO "postgres";
CREATE TABLE "public"."users" (
"id" int4 NOT NULL DEFAULT nextval('users_id_seq'::regclass),
"name" varchar COLLATE "pg_catalog"."default" NOT NULL,
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
)
;
ALTER TABLE "public"."users"
OWNER TO "postgres";
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question