testcontainers / testcontainers/testcontainers-java
[Bug]: Can't create procedure without breaking SQL
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 8.7k
- Forks
- 1.9k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 9
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ScriptUtils, which the report identifies as the component parsing the initial script into transactions. Reproduce the supplied PostgreSQL procedure script with one procedure and then two procedures, including the semicolon after END; done means both scripts execute without unterminated-dollar-quote errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100