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

[Bug]: Can't create procedure without breaking SQL #8059

Open
Mishamba opened this issue Jan 8, 2024 · 2 comments
Open

[Bug]: Can't create procedure without breaking SQL #8059

Mishamba opened this issue Jan 8, 2024 · 2 comments
Labels

Comments

@Mishamba
Copy link

Mishamba commented Jan 8, 2024

Module

PostgreSQL

Testcontainers version

postgres:15.3

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host Arch

x86

Docker version

Server: Docker Desktop 4.26.1 (131620)
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:08:02 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.25
  GitCommit:        d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
 runc:
  Version:          1.1.10
  GitCommit:        v1.1.10-0-g18a0cb0
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

I'm trying to create a procedure with following script

CREATE OR REPLACE PROCEDURE get_user(
    OUT user_ref refcursor,
    IN ID numeric)
    LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
    OPEN user_ref FOR
        SELECT username, create_date
        FROM users
        WHERE id = ID
        ORDER BY modified_dttm;
END;
$BODY$;

And i'm getting next error

Caused by: org.postgresql.util.PSQLException: Unterminated dollar quote started at position 99 in SQL CREATE OR REPLACE PROCEDURE get_user( OUT user_ref refcursor, IN ID numeric) LANGUAGE 'plpgsql' AS $BODY$ BEGIN
    OPEN user_ref FOR
        SELECT username, create_date
        FROM users
        WHERE id = ID
        ORDER BY modified_dttm;
END. Expected terminating $$

It can be solved by removing semicolon after END. After this it works, but only if I try to create one procedure in a row.

CREATE OR REPLACE PROCEDURE get_user(
    OUT user_ref refcursor,
    IN ID numeric)
LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
    OPEN user_ref FOR
        SELECT username, create_date
        FROM users
        WHERE id = ID
        ORDER BY modified_dttm;
END
$BODY$;

But if there two such procedures in a row they wont work. Problem is related with how ScriptUtils parse initial script into transactions.

Relevant log output

Caused by: org.postgresql.util.PSQLException: Unterminated dollar quote started at position 99 in SQL CREATE OR REPLACE PROCEDURE get_user( OUT user_ref refcursor, IN ID numeric) LANGUAGE 'plpgsql' AS $BODY$ BEGIN
    OPEN user_ref FOR
        SELECT username, create_date
        FROM users
        WHERE id = ID
        ORDER BY modified_dttm;
END. Expected terminating $$

Additional Information

No response

@eddumelendez
Copy link
Member

Can you try with Testcontainers 1.19.5, please?

@EvalVis
Copy link

EvalVis commented Mar 17, 2024

@Mishamba
If you try using Testcontainers 1.19.5 and it still does not work could you provide a code snippet on how do you execute the script?

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

3 participants