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

No need to escape question marks in Postgresql #1877

Merged
merged 3 commits into from
Jul 28, 2021
Merged

No need to escape question marks in Postgresql #1877

merged 3 commits into from
Jul 28, 2021

Conversation

nvoxland
Copy link
Contributor

@nvoxland nvoxland commented Jun 1, 2021

I could find no reason for the original code, only problems caused by it.

Fixes #1764
Fixes #1507


Dev Handoff Notes (Internal Use)

Links

Testing

Dev Verification

Tested with sql containing quotes
(No output example saved from previous testing)

Test Requirements (Internal Liquibase QA)

Test Case 1
This test case simplifies the test data provided in #1507. It keeps only the troublesome bit ("?"), as the size of the data file was not the root cause.

	<changeSet author="Liquibase Pro User" id="1::dataForTable-proschema" labels="data">
        <createTable schemaName="proschema" tableName="populated">
			<column name="id" type="NUMBER(20,0)">
			    <constraints nullable="false"/>
			</column>
            <column name="first" type="VARCHAR2(64)"/>
			<column name="last" type="VARCHAR2(64)"/>
        </createTable>
    </changeSet>
	
	<changeSet author="Liquibase Pro User" id="2::dataForTable-proschema" labels="data">
		<loadUpdateData file="data/names.csv" primaryKey="id" tableName="populated" schemaName="proschema"/>
	</changeSet>

The names.csv file contains a row with "?" in it.

id,first,last
1,spongebob,pants
2,john,wick
3,unknown?,unknown?

Verify Liquibase update-sql does not escape the question marks in the 3rd row of data.

  • There should not be a double-question mark in the generated insert statement.
    Verify liquibase update is successful.
  • There is no stack overflow caused by having "?" in insert statements.

Test Case 2
This test case is taken from #1764, which itself came from the forum, https://forum.liquibase.org/t/postgres-functions-and-question-marks/494

<databaseChangeLog 
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd ">

    <changeSet  author="test"  id="1">  
        <sql endDelimiter="/">
CREATE FUNCTION public.x()
    RETURNS void
    LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
INSERT INTO test (results)
SELECT '{"a":1, "b":2}'::jsonb ? 'b';
END;
$BODY$;
/
        </sql>
    </changeSet>
</databaseChangeLog>

_Verify Liquibase update-sql does not escape the question mark in the SELECT statement.

  • There should not be a double-question mark in the generated SQL.
    Verify liquibase update does not cause a stack overflow caused by having "?" in a sql changeset.

Functional Regression Test

  • Add a Postgres-only, functional regression test for Test Case 1 in this ticket.

┆Issue is synchronized with this Jira Story by Unito

@XDelphiGrl
Copy link
Contributor

I could find no reason for the original code, only problems caused by it.

I want to hear this phrase in a song by Radiohead.

@nvoxland nvoxland changed the base branch from master to 4.4.x July 1, 2021 16:58
@sync-by-unito
Copy link

sync-by-unito bot commented Jul 26, 2021

➤ obovsunivskyi commented:

Verified on DAT-1350 #5. Moving to RTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres Functions and Question Marks Regression: StackOverflowError processing large Postgres SQL changeset
4 participants