Comments (7)
Hi,
for my own curiosity I ran it against my own manticore JSQLFormatter.
I think your statement is INVALID as you are missing the BRACKETS around the ON-Expression. Adding the brackets would format the MERGE statement correctly:
-- EXTERNAL
MERGE INTO DW_STG_USER.ACCOUNT_DIM target
USING ( SELECT COMMON_NAME m_commonName
, ORIGIN m_origin
, USAGE_TYPE m_usageType
, CATEGORY m_category
FROM MY_TABLE
WHERE USAGE_TYPE = :value ) source
ON ( source.m_usageType = target.USAGE_TYPE )
WHEN NOT MATCHED THEN
INSERT ( target.COMMON_NAME
, target.ORIGIN
, target.USAGE_TYPE
, target.CATEGORY )
VALUES ( source.m_commonName
, source.m_origin
, source.m_usageType
, source.m_category )
WHEN MATCHED THEN
UPDATE SET target.COMMON_NAME = source.m_commonName
, target.ORIGIN = source.m_origin
, target.USAGE_TYPE = source.m_usageType
, target.CATEGORY = source.m_category
WHERE ( ( source.m_commonName <> target.COMMON_NAME )
OR ( source.m_origin <> target.ORIGIN )
OR ( source.m_usageType <> target.USAGE_TYPE )
OR ( source.m_category <> target.CATEGORY ) )
;
from sql-formatter.
from sql-formatter.
This seems to be fixed on current version.
Thanks @manticore-projects !
from sql-formatter.
Simple statements look better now, but there are still a lot of issues with complex ones, e. g.
-- MERGE 4
MERGE INTO cfe.instrument_import_measure imp
USING ( WITH x AS (
SELECT a.id_instrument
, a.id_currency
, a.id_instrument_type
, b.id_portfolio
, c.attribute_value product_code
, t.valid_date
, t.yield
FROM cfe.instrument a
INNER JOIN cfe.impairment b
ON a.id_instrument = b.id_instrument
LEFT JOIN cfe.instrument_attribute c
ON a.id_instrument = c.id_instrument
AND c.id_attribute = 'product'
INNER JOIN cfe.ext_yield t
ON ( a.id_currency = t.id_currency )
AND ( a.id_instrument_type LIKE t.id_instrument_type )
AND ( b.id_portfolio LIKE t.id_portfolio
OR ( b.id_portfolio IS NULL
AND t.id_portfolio = '%' ) )
AND ( c.attribute_value LIKE t.product_code
OR ( c.attribute_value IS NULL
AND t.product_code = '%' ) ) )
SELECT /*+ PARALLEL */ *
FROM x x1
WHERE x1.valid_date = ( SELECT max
FROM x
WHERE id_instrument = x1.id_instrument
AND valid_date <= to_date ) ) s
ON ( imp.id_instrument = s.id_instrument
AND imp.measure = 'YIELD_PP' )
WHEN MATCHED THEN
UPDATE SET imp.value = s.yield
;
You can have a look at https://github.com/manticore-projects/jsqlformatter and also benchmark it against the interactive DEMO. Maybe the provided samples and test cases will be helpful.
from sql-formatter.
Btw, how do you plan to deal with comments? Example
-- BOTH CLAUSES PRESENT 'with a string' AND "a field"
MERGE /*+ PARALLEL */ INTO test1 /*the target table*/ a
USING all_objects /*the source table*/
ON ( /*joins in()!*/ a.object_id = b.object_id )
-- INSERT CLAUSE
WHEN /*comments between keywords!*/ NOT MATCHED THEN
INSERT ( object_id /*ID Column*/
, status /*Status Column*/ )
VALUES ( b.object_id
, b.status )
/* UPDATE CLAUSE
WITH A WHERE CONDITION */
WHEN MATCHED THEN /* Lets rock */
UPDATE SET a.status = '/*this is no comment!*/ and -- this ain''t either'
WHERE b."--status" != 'VALID'
;
Had a really hard time to figure that out.
So maybe we should just join our efforts and work together? One 90% solution would be better than 2 different 75% solution in my opinion.
from sql-formatter.
That's a good idea, but I think the advantage of this library is having no dependencies, as described in readme.
And about formatting, currently, my priority is to reproduce the behavior of original library, https://github.com/zeroturnaround/sql-formatter.
But, there are a few bugs or issues in the original version, so I'm now wondering if I should improve it independently...
from sql-formatter.
I almost completely agree with you, there is no doubt that JSQLFormatter is more reliable at formatting.
But, why I ported this is the original is very simple implementation by using REGEX.
And now, there is an issue about using external SQL parser created by maintainer of original.
sql-formatter-org/sql-formatter#117
As mentioned in this, to make pluggable the use of external parser might be the better solution, I think.
Thank you very much too.
from sql-formatter.
Related Issues (20)
- java.util.Date query parameters not put in correctly
- Formatting issue after LIKE Predicate Escape Character '\' HOT 3
- Release 1.0.4 HOT 2
- v2.0.0 String '||' issue HOT 1
- need additional space in ALTER TABLE ADD HOT 2
- is format() thread safe? HOT 1
- @@ operator splitting in Postgres HOT 2
- Splitting table name with $ on PostgreSQL HOT 1
- Oracle quotation operation fails HOT 2
- jdbc named parameter support HOT 2
- Extra space inserted inside backtick strings HOT 2
- Extra whitespace inserted in string concatenation operator HOT 1
- Question: getTableNames from SQL Statement? HOT 1
- Named placeholders are broken due to whitespace HOT 3
- Add @@SESSION as reserved word for MySQL HOT 2
- Is there any way to set "Indentation style: Tabular, Right"? HOT 1
- Escape character + escaped double quote makes formatted SQL invalid HOT 1
- Formatter inserts space in between "//" (this is vertica's integer division operator) HOT 1
- Issue when column name contains escaped enclosing character HOT 5
- Contains spaces.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sql-formatter.