Skip to content

Instantly share code, notes, and snippets.

@beginor
Last active September 27, 2018 07:56
Show Gist options
  • Select an option

  • Save beginor/3bb328bf7d74ddac00f924c077a7163d to your computer and use it in GitHub Desktop.

Select an option

Save beginor/3bb328bf7d74ddac00f924c077a7163d to your computer and use it in GitHub Desktop.
postgres for loop
DO $$
DECLARE
st_time TIMESTAMP WITH TIME ZONE := '2016-03-01';
p RECORD;
BEGIN
RAISE INFO 'stat time is: % :', st_time;
FOR p IN
SELECT
r.id, r.water_source_code, r.water_source_name
FROM public.water_source_month_report r
WHERE r.stat_time = st_time and r.water_source_code <> ''
LOOP
RAISE INFO '%', p;
END LOOP;
END $$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment