Unexpected parsing of an invalid CREATE TABLE statement

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Unexpected parsing of an invalid CREATE TABLE statement

Shawn Wagner
Consider:

CREATE TABLE a(id INTEGER PRIMARY KEY);
CREATE TABLE b(id INTEGER PRIMARY KEY);
CREATE TABLE c(id INTEGER PRIMARY KEY, a_id, b_id,
               FOREIGN KEY (a_id) REFERENCES a(id)
               FOREIGN KEY (b_id) REFERENCES b(id));

Note the lack of comma between the two foreign key constraints in the
definition for table c. The syntax diagrams in the documentation indicate
that the comma is mandatory, but not only does this not cause a parse
error, but both of them are detected:

sqlite> PRAGMA foreign_key_list(c);
id          seq         table       from        to          on_update
on_delete   match
----------  ----------  ----------  ----------  ----------  ----------
 ----------  ----------
0           0           b           b_id        id          NO ACTION   NO
ACTION   NONE
1           0           a           a_id        id          NO ACTION   NO
ACTION   NONE
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Unexpected parsing of an invalid CREATE TABLE statement

Richard Hipp-3
On 6/10/19, Shawn Wagner <[hidden email]> wrote:

> Consider:
>
> CREATE TABLE a(id INTEGER PRIMARY KEY);
> CREATE TABLE b(id INTEGER PRIMARY KEY);
> CREATE TABLE c(id INTEGER PRIMARY KEY, a_id, b_id,
>                FOREIGN KEY (a_id) REFERENCES a(id)
>                FOREIGN KEY (b_id) REFERENCES b(id));
>
> Note the lack of comma between the two foreign key constraints in the
> definition for table c. The syntax diagrams in the documentation indicate
> that the comma is mandatory, but not only does this not cause a parse
> error, but both of them are detected:
>

The parser in SQL is very forgiving.  Does this cause some kind of problem?

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Unexpected parsing of an invalid CREATE TABLE statement

Shawn Wagner
Forgiving, yes, but usually not /that/ forgiving. It's certainly caused
some wasted time going down the wrong path trying to debug an issue.


On Mon, Jun 10, 2019 at 3:39 PM Richard Hipp <[hidden email]> wrote:

> On 6/10/19, Shawn Wagner <[hidden email]> wrote:
> > Consider:
> >
> > CREATE TABLE a(id INTEGER PRIMARY KEY);
> > CREATE TABLE b(id INTEGER PRIMARY KEY);
> > CREATE TABLE c(id INTEGER PRIMARY KEY, a_id, b_id,
> >                FOREIGN KEY (a_id) REFERENCES a(id)
> >                FOREIGN KEY (b_id) REFERENCES b(id));
> >
> > Note the lack of comma between the two foreign key constraints in the
> > definition for table c. The syntax diagrams in the documentation indicate
> > that the comma is mandatory, but not only does this not cause a parse
> > error, but both of them are detected:
> >
>
> The parser in SQL is very forgiving.  Does this cause some kind of problem?
>
> --
> D. Richard Hipp
> [hidden email]
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users