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

query statements may not start using the 'WITH' keyword #984

Closed
leonschenk opened this issue Sep 15, 2023 · 2 comments · Fixed by #985
Closed

query statements may not start using the 'WITH' keyword #984

leonschenk opened this issue Sep 15, 2023 · 2 comments · Fixed by #985
Labels
good first issue A good point to start from for new contributrs Prio: High Type: Bug

Comments

@leonschenk
Copy link

Citrus Version
3.4.0

Expected behavior
The statement/query, starting with the keyword 'WITH' instead of 'SELECT' will be executed.

Actual behavior
Exception is thrown while validating the statement, before executing.

Test case sample

enter a recursive query like the following (example taken from source https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-recursive-query/)
query is not executed because of ExecuteSqlQueryAction.validateSqlStatement

query(dataSource).statement("WITH RECURSIVE subordinates AS (
	SELECT
		employee_id,
		manager_id,
		full_name
	FROM
		employees
	WHERE
		employee_id = 2
	UNION
		SELECT
			e.employee_id,
			e.manager_id,
			e.full_name
		FROM
			employees e
		INNER JOIN subordinates s ON s.employee_id = e.manager_id
) SELECT
	*
FROM
	subordinates;").build();

Workaround:

testRunner.run(new ExecuteSQLQueryAction(sqlQueryActionBuilder) {
    @Override
    protected void validateSqlStatement(final String stmt) {
        if (!(stmt.toLowerCase().startsWith("select") || stmt.toLowerCase().startsWith("with"))) {
            throw new CitrusRuntimeException("Missing keyword SELECT or WITH in statement: " + stmt);
        }
    }
});
@bbortt bbortt added Type: Bug Prio: High good first issue A good point to start from for new contributrs labels Sep 15, 2023
@bbortt
Copy link
Collaborator

bbortt commented Sep 15, 2023

that is a good report! the WITH clause (also known as Common Table Expressions (CTEs)) is part of the SQL standard SQL:1999. according to the list of SQL reserved words all modern databases support it (as they should). it is therefore not PostgreSQL specific.

I think it's fair to say that fix would be welcome:

do you need it backported to 3.x, or is it okay to include into 4.x @leonschenk?

@leonschenk
Copy link
Author

@bbortt thank you! I will be fine with the workaround for now.

bbortt added a commit that referenced this issue Sep 15, 2023
the `WITH` clause (also known as Common Table Expressions (CTEs)) is part of the SQL standard SQL:1999.
according to the [list of SQL reserved words](https://en.wikipedia.org/wiki/List_of_SQL_reserved_words)
all modern databases support it (as they should).
bbortt added a commit that referenced this issue Sep 18, 2023
allow WITH sql keyword for query action
bbortt added a commit that referenced this issue Oct 6, 2023
chore: remove automatic sql variable extraction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue A good point to start from for new contributrs Prio: High Type: Bug
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants