PL/SQL parser - Phase 2 (MDEV-10764)

[MDEV-12087] sql_mode=ORACLE: a new option to make dash-dash to start a comment Created: 2017-02-20  Updated: 2023-10-20

Status: Open
Project: MariaDB Server
Component/s: Parser
Affects Version/s: None
Fix Version/s: None

Type: Technical task Priority: Minor
Reporter: Alexander Barkov Assignee: Unassigned
Resolution: Unresolved Votes: 2
Labels: Compatibility, Oracle

Issue Links:
Duplicate
is duplicated by MDEV-19728 Comments in SQL Closed

 Description   

Oracle uses the SQL standard syntax for simple comments: dash-dash starts a comment, the rest of the line is a comment.

DROP PROCEDURE p1;
CREATE PROCEDURE p1 AS
BEGIN
  --This is a comment
  NULL;
END;
/

MariaDB uses non-standard syntaxt: dash-dash-space starts a comment. This is an example of a valid script:

SET sql_mode=DEFAULT;
DROP PROCEDURE p1;
DELIMITER /
CREATE PROCEDURE p1()
BEGIN
  -- This is a comment
END;
/
DELIMITER ;

If I remove the space character after "--", it returns a syntax error:

SET sql_mode=DEFAULT;
DROP PROCEDURE p1;
DELIMITER /
CREATE PROCEDURE p1()
BEGIN
  --This is a comment
END;
/
DELIMITER ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '--This is a comment
END' at line 3

That was an intentional design in early MySQL versions:
https://dev.mysql.com/doc/refman/5.7/en/ansi-diff-comments.html

We should add an option to make dash-dash without an extra space start a comment, as it makes migration from Oracle difficult.

Perhaps, a new flag in sql_mode or old_mode can solve the issue.



 Comments   
Comment by Sergei Golubchik [ 2019-06-11 ]

dash-dash with no space is the sql standard syntax, MariaDB should support it not only in the ORACLE mode.

Comment by Sergei Golubchik [ 2019-06-12 ]

The problem comes from the syntax like SELECT --1 — this is valid both in MariaDB and Oracle, and means SELECT 1. But in the standard SQL -- starts a comment, the standard does not allow more than one <minus sign> before a number (so it seems).

I don't think we can implement the standard behavior, it'll be a pretty serious compatibility break.

Generated at Thu Feb 08 07:55:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.