Mega Code Archive

 
Categories / PostgreSQL / Postgre SQL
 

Simple While LOOP

postgres=# postgres=# CREATE FUNCTION "count_by_two" (integer) RETURNS integer AS ' postgres'#      DECLARE postgres'#           userNum ALIAS FOR $1; postgres'#           i integer; postgres'#      BEGIN postgres'#           i := 1; postgres'#           WHILE userNum < 20 LOOP postgres'#                 i = i+1; postgres'#                 return userNum; postgres'#           END LOOP; postgres'# postgres'#      END; postgres'#    ' LANGUAGE 'plpgsql'; CREATE FUNCTION postgres=# postgres=# select count_by_two(12);  count_by_two --------------            12 (1 row) postgres=#