Skip to content

Unable to correctly identify the use of escape characters and percent signs in LIKE statements #80

@CppcOwn

Description

@CppcOwn

Original SQL

and (
            
                
                (
                upper(
                
                        m.name
                    
                ) like '%1111%'  escape '\' 
                )
            
                
                    
                            or
                        
                
                (
                upper(
                
                        m.partnumber
                    
                ) like '%1111%'  escape '\' 
                )
            
            )  

Format

FormatConfig config = FormatConfig.builder().indent("  ").linesBetweenQueries(1).build();
SqlFormatter.of(DbType.postgresql).format(sql, config)

Result
like ' % 1111 % ' escape ' \ '
During the formatting process, the formatter treats the percent sign (%) as a modulo operator, rather than as part of the LIKE expression. Similarly, the back slash () is also treated as a regular character separated by spaces。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions