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

plpgsql: support accessing variables via label.var_name pattern #122322

Open
yuzefovich opened this issue Apr 13, 2024 · 0 comments
Open

plpgsql: support accessing variables via label.var_name pattern #122322

yuzefovich opened this issue Apr 13, 2024 · 0 comments
Labels
A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-known-limitation O-qa T-sql-queries SQL Queries Team

Comments

@yuzefovich
Copy link
Member

yuzefovich commented Apr 13, 2024

This works in Postgres:

DROP PROCEDURE IF EXISTS p;
CREATE PROCEDURE p() LANGUAGE PLpgSQL AS $$
BEGIN
    <<label>>
    DECLARE
      v text := 'test';
    BEGIN
        RAISE NOTICE '%', label.v;
    END;
END;
$$;

Note that support for this access pattern makes sense the most when variable shadowing is allowed (#117508).

Relatedly, it's possible to access the input arguments via routine-name.arg-name pattern:

DROP PROCEDURE IF EXISTS p;
CREATE PROCEDURE p(param1 INT, param2 TEXT) LANGUAGE PLpgSQL AS $$
BEGIN
    RAISE NOTICE '% %', p.param1, p.param2;
END;
$$;
CALL p(3, 'foo');

Jira issue: CRDB-37800

@yuzefovich yuzefovich added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-qa T-sql-queries SQL Queries Team A-sql-routine UDFs and Stored Procedures labels Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) docs-known-limitation O-qa T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

1 participant