Git Product home page Git Product logo

Comments (6)

PhilippSalvisberg avatar PhilippSalvisberg commented on May 28, 2024

I agree that the formatting of conditions with parenthesis is not optimal. The change is for sure not simple.

from plsql-formatter-settings.

wienerri avatar wienerri commented on May 28, 2024

I think you are master of this code - If you think that required workload is not appropriate to required benefit, it is correct situation and we can close this issue.

from plsql-formatter-settings.

PhilippSalvisberg avatar PhilippSalvisberg commented on May 28, 2024

It's a valid issue. Therefore I like to keep it open for the time being.

I need a bit more time to think about it. In the end the formatting rules should be consistent. Currently the original SQLDev right-aligning strategy for AND and OR is consistent. It looks strange with parenthesis or even when mixing AND and OR conditions without parenthesis. But it is okay for a series of AND-only or OR-only conditions.

from plsql-formatter-settings.

PhilippSalvisberg avatar PhilippSalvisberg commented on May 28, 2024

Here's another way to format it which has some consistent logic (treating AND and OR with parenthesis like functions) but looks strange.

SELECT *
  FROM dba_tables
 WHERE ( 
          owner = 'SYSTEM'
          AND ( 
             table_name = 'REDO_DB'
             OR table_name = 'REDO_LOG'
          )
       ) OR (
          owner = 'SYS'
          AND (
             table_name = 'ALERT_QT'
             OR table_name = 'ALL_UNIFIED_AUDIT_ACTIONS'
          )
       );

When formatting the code by hand the result would be much more compact. Something like this:

SELECT *
  FROM dba_tables
 WHERE (owner = 'SYSTEM' AND (table_name = 'REDO_DB' OR table_name = 'REDO_LOG'))
    OR (owner = 'SYS' AND (table_name = 'ALERT_QT' OR table_name = 'ALL_UNIFIED_AUDIT_ACTIONS'));

So, this is also related to line size and line breaks as we discussed it in issue #33. In this case it's not arguments it's the number of sub-conditions. As soon as we are going to add line breaks to conditions the things become a bit complicated.

from plsql-formatter-settings.

wienerri avatar wienerri commented on May 28, 2024

It looks pretty good.
I think there is a similar issue in pl/SQL:

begin
   if ( ( 1 = 2 ) or ( (
      2 = 2 and 3 = 3
   ) or ( 4 = 5 ) ) ) then
      dbms_output.put_line('Yes');
   end if;
end;

from plsql-formatter-settings.

PhilippSalvisberg avatar PhilippSalvisberg commented on May 28, 2024

Formatting this input:

select * from dba_tables where (owner = 'SYSTEM' and (table_name = 'REDO_DB' or table_name = 'REDO_LOG')) or (owner = 'SYS' and (table_name = 'ALERT_QT' or table_name = 'ALL_UNIFIED_AUDIT_ACTIONS'));

with the intermediate version of lightweight formatter (see #105) produces this result:

select *
  from dba_tables
 where (owner = 'SYSTEM' and (table_name = 'REDO_DB' or table_name = 'REDO_LOG'))
    or (owner = 'SYS' and (table_name = 'ALERT_QT' or table_name = 'ALL_UNIFIED_AUDIT_ACTIONS'));

from plsql-formatter-settings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.