Aşağıdaki şekilde 1 fonksiyon yazdım, zaten en az 1 adet istenilmiş, alternatif olarak 1 tane daha yazdım.
- Seçilen stadyum'un ölçümlerini tablo olarak listeliyor. aşağıdaki şekilde kullanılır.
SELECT * FROM stadyum_olcumleri(1); -- 1, seçilen stadyumun kimliği
CREATE OR REPLACE FUNCTION stadyum_olcumleri(stadium_id integer) RETURNS TABLE ( "Id" integer, "StadiumId" integer, "MeasureDate" date, "Temperature" double precision, "Humidity" double precision, "ExpectedWeatherTypeId" integer, "Hour" integer ) AS $$ BEGIN RETURN QUERY SELECT "Id", "StadiumId", "MeasureDate", "Temperature", "Humidity", "ExpectedWeatherTypeId", "Hour" FROM public."StadiumMeasuring" WHERE "StadiumId" = stadium_id; END; $$ LANGUAGE plpgsql;
- seçilen il ve ilçelerin hava durumu
SELECT * FROM il_ilce_havadurumu(1, 1); -- 1, seçilen ilin kimliği; 1, seçilen ilçenin kimliği
CREATE OR REPLACE FUNCTION il_ilce_havadurumu(city_id integer, district_id integer) RETURNS TABLE ( "Id" integer, "Tarih" timestamp without time zone, "IstasyonId" integer, "ParametreId" integer, "Deger" double precision ) AS $$ BEGIN RETURN QUERY SELECT "Id", "Tarih", "IstasyonId", "ParametreId", "Deger" FROM public.olcumler JOIN public.istasyonlar ON public.olcumler."IstasyonId" = public.istasyonlar."Id" WHERE public.istasyonlar."SehirId" = city_id AND public.istasyonlar."IlceId" = district_id; END; $$ LANGUAGE plpgsql;