ansi-sql

How to test SQL for validity from the command line?

假装没事ソ 提交于 2019-12-01 15:37:57
问题 Is there a good tool for ensuring that an SQL query is valid ANSI SQL, and optionally what DBMSs will fail to interpret it? I've found http://developer.mimer.com/validator but I was wondering whether there is a command line tool, preferably open source. 回答1: Here is a SQL Library that can help you to do vendor-specific offline SQL syntax check via command line, both Java and .NET demo were available. 回答2: Maybe a parser/generator like ANTLR or JavaCC has an ANSI SQL 92 grammar already built.

Implement Rank without using analytic function

ぐ巨炮叔叔 提交于 2019-12-01 01:55:22
I am wondering if there is a method to implement SQL analytic functions without using the inbuilt functions. Can someone help me with this. Thank you. SELECT *, ROW_NUMBER() OVER( PARTITION BY dept_id ORDER BY salary DESC ) AS rownum, DENSE_RANK() OVER( PARTITION BY dept_id ORDER BY salary DESC ) AS denserank, RANK() OVER( PARTITION BY dept_id ORDER BY salary DESC ) AS rnk FROM emp; Here are the three equivalent expressions: select emp.*, (select count(*) from emp emp2 where emp2.dept_id = emp.dept_id and (emp2.salary > emp.salary or emp2.salary = emp.salary and emp2.emp_id <= emp.emp_id ) )

Is there an ANSI Specification for the PIVOT statement?

天大地大妈咪最大 提交于 2019-11-30 23:52:00
Lately I asked the question How can I use PIVOT to show simultaneous average and count in its cells? The question is answered for SQL-Server (2005+) and Oracle (11g +) Obviously the sql-server implementation is rather limited and Oracle implementation yields strange column names. Are these independent solutions or are there based on some ANSI-standards? It isn't in ANSI-92 . The later versions are not freely available (as far as I can tell) except a draft SQL:2003 . Also not mentioned Note: neither pivot nor cross-tab are mentioned 来源: https://stackoverflow.com/questions/4842726/is-there-an

Is there an ANSI Specification for the PIVOT statement?

南笙酒味 提交于 2019-11-30 19:30:12
问题 Lately I asked the question How can I use PIVOT to show simultaneous average and count in its cells? The question is answered for SQL-Server (2005+) and Oracle (11g +) Obviously the sql-server implementation is rather limited and Oracle implementation yields strange column names. Are these independent solutions or are there based on some ANSI-standards? 回答1: It isn't in ANSI-92. The later versions are not freely available (as far as I can tell) except a draft SQL:2003. Also not mentioned Note

Database Engines and ANSI SQL Compliance

谁说胖子不能爱 提交于 2019-11-30 03:43:51
I've been searching for half an hour and can't find any resources stating what level of the SQL ANSI standard is supported on various database engines. It looks like some level of support is provided by most engines, but I'd like to know exactly what level is officially supported. I'm primarily interested in MySQL, PostgreSQL, SQL Server, and Oracle. EDIT: PostgreSQL has a great page on compliance, exactly what I was looking for regarding the other engines: http://www.postgresql.org/docs/current/interactive/features.html these might help a little: Comparison of different SQL implementations

Comparisons with NULLs in SQL

雨燕双飞 提交于 2019-11-29 10:51:24
ANSI-92 SQL mandates that comparisons with NULL evaluate to "falsy," eg: SELECT * FROM table WHERE field = NULL SELECT * FROM table WHERE field != NULL Will both return no rows because NULL can't be compared like that. Instead, the predicates IS NULL and IS NOT NULL have to be used instead: SELECT * FROM table WHERE field IS NULL SELECT * FROM table WHERE field IS NOT NULL Research has shown me that Oracle 1 , PostgreSQL, MySQL and SQLite all support the ANSI syntax. Add to that list DB2 and Firebird. Aside from SQL Server with ANSI_NULLS turned off, what other RDBMS support the non-ANSI

There are a method to paging using ANSI SQL only?

懵懂的女人 提交于 2019-11-29 09:59:02
I know: Firebird: FIRST and SKIP ; MySQL: LIMIT ; SQL Server: ROW_NUMBER() ; Does someone knows a SQL ANSI way to perform result paging? See Limit—with offset section on this page: http://troels.arvin.dk/db/rdbms/ BTW, Firebird also supports ROWS clause since version 2.0 No official way, no.* Generally you'll want to have an abstracted-out function in your database access layer that will cope with it for you; give it a hint that you're on MySQL or PostgreSQL and it can add a 'LIMIT' clause to your query, or rownum over a subquery for Oracle and so on. If it doesn't know it can do any of those,

Does the order of tables in a join matter, when LEFT (outer) joins are used?

独自空忆成欢 提交于 2019-11-29 07:06:14
I would like to confirm that the SQL query SELECT .... FROM apples, oranges LEFT JOIN kiwis ON kiwis.orange_id = oranges.id, bananas WHERE .... is exactly equivalent to other permutations in the FROM subclause, like SELECT .... FROM oranges LEFT JOIN kiwis ON kiwis.orange_id = oranges.id, bananas, apples WHERE .... or SELECT .... FROM bananas, apples, oranges LEFT JOIN kiwis ON kiwis.orange_id = oranges.id WHERE .... as long as the explicit LEFT JOIN between oranges and kiwis remains intact. From what I've read in various documents, the returned set should be exactly the same. I'm really only

Standard SQL boolean operator IS vs. equals (=) operator

扶醉桌前 提交于 2019-11-29 05:33:26
On the Wikipedia page for SQL there are some truth tables about boolean logic in SQL. [1] The Wikipedia page seems to source the SQL:2003 standard. The truth table for the equals operator (=) is different from the IS operator from the SQL:2003 draft. Also, the Wikipedia article notes that "IS NULL" (<null predicate>) is a special case. In the SQL:2003 it seems that there is an "IS" opeartor which is a regular operator like AND, NOT and OR. However, the <null predicate> is still there. Why is the <null predicate> there when the IS is a regular boolean operator? Is it to make sure you can use

SQL Joins: Future of the SQL ANSI Standard (where vs join)?

Deadly 提交于 2019-11-28 12:12:15
We are developing ETL jobs and our consultant has been using "old style" SQL when joining tables select a.attr1, b.attr1 from table1 a, table2 b where a.attr2 = b.attr2 instead of using the inner join clause select a.attr1, b.attr1 from table1 as a inner join table2 as b on a.attr2 = b.attr2 My question is that in the long run, is there a risk for using the old "where join"? How long this kind of joins are supported and kept as ANSI standard? Our platform is SQL Server and my primary cause is that in the future these "where joins" are no longer supported. When this happens, we have to modify