Created
June 14, 2014 20:06
-
-
Save happysundar/056f3cf848de054b9cda to your computer and use it in GitHub Desktop.
Creating a plpgsql function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP FUNCTION IF EXISTS get_image_records( BIGINT ) CASCADE; | |
CREATE OR REPLACE FUNCTION | |
get_image_records(input_program_id BIGINT) | |
RETURNS SETOF JSON STABLE | |
AS $$ | |
BEGIN | |
RETURN QUERY | |
WITH T2 AS ( | |
SELECT | |
file_url :: TEXT, | |
file_height, | |
file_width, | |
file_size, | |
number_of_people, | |
zoom_level, | |
caption :: TEXT, | |
primary_image, | |
image_type_name :: TEXT | |
FROM export.programimages_imagefiles | |
WHERE programimages_imagefiles.program_id = input_program_id) | |
SELECT | |
json_agg(to_json(T2.*)) | |
FROM T2; | |
END | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment