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

Add SQL dialect for DB2 for IBM i #658

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions test/features/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,43 @@ export default function supportsJoin(
const result = format(`
SELECT * FROM customers
${join} orders ON customers.customer_id = orders.customer_id
${join} items ON items.id = orders.id;
${join} items ON items.col1 = orders.col1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really the case that unquoted id can't be used as a column name in DB2 i?

When I look at the reserved word lists of LUW-version and Z-version the ID indeed doesn't appear in reserved words list.

However I still find it surprising that a) one would need to quote such a commonly used column name b) there's such a striking difference between the i-version of DB2 from other DB2 dialects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reserved words list for DB2 for IBM i shows ID as a reserved word - but I haven't tested if ID is allowed in the context of a column name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled into the ID problem when I activated JOIN ... USING - suddenly the tests failed for DB2i because ID was converted to uppercase by the formatter. So I changed the id in the test to a more generic column name.

Just tested id ad a column name on DB2 for i - and it is indeed allowed... Is it better to remove ID from the reserved words list?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please test this?

I remember seeing ID in the keywords list of some other SQL dialects, but it has always turned out that it's not really a reserved keyword.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Best to just remove it from reserved words list. Given that this list has currently like 500 words, my suspicion is that many more of these keywords are actually not reserved.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered a similar problem when trying to find out which keywords does SingleStoreDB actually reserve. Their documentation only listed all the keywords and didn't distinguish which ones are reserved and which ones were not. I ended up executing hundreds of SQL queries to see which would actually result in a failure.

`);
expect(result).toBe(dedent`
SELECT
*
FROM
customers
${join} orders ON customers.customer_id = orders.customer_id
${join} items ON items.id = orders.id;
${join} items ON items.col1 = orders.col1;
`);
});
});

it('properly uppercases JOIN ... ON', () => {
const result = format(`select * from customers join foo on foo.id = customers.id;`, {
const result = format(`select * from customers join foo on foo.col1 = customers.col1;`, {
keywordCase: 'upper',
});
expect(result).toBe(dedent`
SELECT
*
FROM
customers
JOIN foo ON foo.id = customers.id;
JOIN foo ON foo.col1 = customers.col1;
`);
});

if (supportsUsing) {
it('properly uppercases JOIN ... USING', () => {
const result = format(`select * from customers join foo using (id);`, {
const result = format(`select * from customers join foo using (col1);`, {
keywordCase: 'upper',
});
expect(result).toBe(dedent`
SELECT
*
FROM
customers
JOIN foo USING (id);
JOIN foo USING (col1);
`);
});
}
Expand All @@ -87,13 +87,13 @@ export default function supportsJoin(
['CROSS APPLY', 'OUTER APPLY'].forEach(apply => {
// TODO: improve formatting of custom functions
it(`supports ${apply}`, () => {
const result = format(`SELECT * FROM customers ${apply} fn(customers.id)`);
const result = format(`SELECT * FROM customers ${apply} fn(customers.col1)`);
expect(result).toBe(dedent`
SELECT
*
FROM
customers
${apply} fn (customers.id)
${apply} fn (customers.col1)
`);
});
});
Expand Down
Loading