Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psql queries with functions not properly separated #47

Open
MasterOdin opened this issue Oct 29, 2021 · 0 comments
Open

psql queries with functions not properly separated #47

MasterOdin opened this issue Oct 29, 2021 · 0 comments
Labels

Comments

@MasterOdin
Copy link
Member

Test query:

CREATE OR REPLACE FUNCTION f_grp_prod(text)
  RETURNS TABLE (
    name text
  , result1 double precision
  , result2 double precision)
LANGUAGE plpgsql STABLE
AS
$$
DECLARE
    r      mytable%ROWTYPE;
    _round integer;
BEGIN
    -- init vars
    name    := $1;
    result2 := 1;       -- abuse result2 as temp var for convenience
FOR r IN
    SELECT *
    FROM   mytable m
    WHERE  m.name = name
    ORDER  BY m.round
LOOP
    IF r.round <> _round THEN   -- save result1 before 2nd round
        result1 := result2;
        result2 := 1;
    END IF;
    result2 := result2 * (1 - r.val/100);
    _round  := r.round;
END LOOP;
RETURN NEXT;
END;
$$;

SELECT * FROM foo;

The identifier only returns one function instead of two.

@MasterOdin MasterOdin added the bug label Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant