0

I was looking to just know how to declare variable in a sql file for a PG db so I just try this :

DO $$
DECLARE 
    i INT := 0;
BEGIN
    WHILE i <= numberUsers
    BEGIN
        SELECT COUNT(*) FROM "Users";
        SET i := i + 1;
    END;
END $$;

Now I have this result :

psql:matching.sql:10: ERREUR:  « LOOP » manquant à la fin de l'expression SQL
LIGNE 7 :         SELECT COUNT(*) FROM "Users";

So it seems to not work.

Kind regards !

  • 1
    Does this answer your question? [How to declare a variable in a PostgreSQL query](https://stackoverflow.com/q/1490942/1260204) – Igor Mar 26 '21 at 15:28
  • 1
    Does this answer your question? [How to declare local variables in postgresql?](https://stackoverflow.com/q/3157753/1260204) – Igor Mar 26 '21 at 15:29

0 Answers0