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

sql: calling EXECUTE in PL/pgSQL should return more helpful error #123672

Closed
rytaft opened this issue May 6, 2024 · 1 comment · Fixed by #124886
Closed

sql: calling EXECUTE in PL/pgSQL should return more helpful error #123672

rytaft opened this issue May 6, 2024 · 1 comment · Fixed by #124886
Assignees
Labels
A-sql-routine UDFs and Stored Procedures C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-quick-win Likely to be a quick win for someone experienced. O-qa T-sql-queries SQL Queries Team

Comments

@rytaft
Copy link
Collaborator

rytaft commented May 6, 2024

When I run the following on 24.1:

CREATE TABLE mytable (inserted_by TEXT, inserted TIMESTAMP);
CREATE TABLE c (checked_user TEXT, checked_date TIMESTAMP);

CREATE PROCEDURE test(checked_user TEXT, checked_date TIMESTAMP)
AS $$
DECLARE
  c INT;
BEGIN
  EXECUTE 'SELECT count(*) FROM mytable WHERE inserted_by = $1 AND inserted <= $2'
    INTO c
    USING checked_user, checked_date;
END;
$$ LANGUAGE plpgsql;

CALL test('blah', now()::timestamp);

I get the error:

ERROR: unimplemented: attempted to use a PL/pgSQL statement that is not yet supported
SQLSTATE: 0A000
HINT: You have attempted to use a feature that is not yet implemented.

Please check the public issue tracker to check whether this problem is
already tracked. If you cannot find it there, please report the error
with details by creating a new issue.

If you would rather not post publicly, please contact us directly
using the support form.

We appreciate your feedback.

It's not clear exactly which statement is unsupported. Ideally this error would specify the EXECUTE command and reference the dynamic SQL issue: #115300

Jira issue: CRDB-38463

@rytaft rytaft added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. O-qa T-sql-queries SQL Queries Team A-sql-routine UDFs and Stored Procedures labels May 6, 2024
@michae2
Copy link
Collaborator

michae2 commented May 7, 2024

Same error when creating a SP like the following:

CREATE TABLE t6 (a int);

CREATE PROCEDURE p6(IN i int)
LANGUAGE plpgsql
AS $$
BEGIN
  INSERT INTO t6 VALUES (i);
  CASE i
    WHEN 6 THEN
      COMMIT;
    WHEN 7 THEN
      ROLLBACK;
    WHEN 8 THEN
      COMMIT;
    ELSE
      ROLLBACK;
  END CASE;
END;
$$;

It would help to point out the statement (and maybe even the line number?) that is unsupported.

@DrewKimball DrewKimball added the E-quick-win Likely to be a quick win for someone experienced. label May 21, 2024
@DrewKimball DrewKimball self-assigned this May 21, 2024
DrewKimball added a commit to DrewKimball/cockroach that referenced this issue May 30, 2024
This patch augments the error for attempted use of an unsupported PL/pgSQL
statement with the statement tag, so that it's easier for the user to
indentify the unsupported statement.

Fixes cockroachdb#123672

Release note: None
craig bot pushed a commit that referenced this issue May 31, 2024
124886: plpgsql: improve the unsupported statement error message r=DrewKimball a=DrewKimball

This patch augments the error for attempted use of an unsupported PL/pgSQL statement with the statement tag, so that it's easier for the user to indentify the unsupported statement.

Fixes #123672

Release note: None

Co-authored-by: Drew Kimball <drewk@cockroachlabs.com>
@craig craig bot closed this as completed in 2c67c77 May 31, 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-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. E-quick-win Likely to be a quick win for someone experienced. O-qa T-sql-queries SQL Queries Team
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants