docs: ColumnOption::ForeignKey docs have wrong SQL syntax

Open Beginner friendly
#1,761 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
72/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
documentation

Research direction

Open the linked docs.rs page and locate the ColumnOption::ForeignKey documentation in the repository source. Verify the column-constraint syntax against the examples in the issue, then correct the syntax description and place the large syntax literal in its own paragraph. Done means the generated documentation describes valid column syntax without the table-constraint FOREIGN KEY prefix.

Written by the indexing model from the issue text.

Description

https://docs.rs/sqlparser/0.55.0/sqlparser/ast/enum.ColumnOption.html#variant.ForeignKey

says

A referential integrity constraint ([FOREIGN KEY REFERENCES <foreign_table> (<referred_columns>) { [ON DELETE <referential_action>] [ON UPDATE <referential_action>] | [ON UPDATE <referential_action>] [ON DELETE <referential_action>] } [<constraint_characteristics>]).

I believe the FOREIGN KEY (name) REFERENCES syntax is only for table constraints. That's why it has to say which source columns it talks about!

I believe the syntax for column constraints is just col_name REFERENCES othertable (othercolumn).

As far as I can tell, the sqlparser-rs is already correct. For example, this won't parse:

-- wrong
CREATE TABLE myschema.mytable (
  mycolumn BIGINT NOT NULL,
  PRIMARY KEY(mycolumn),
  bar BIGINT FOREIGN KEY REFERENCES foo (bar));

This does:

-- good
CREATE TABLE myschema.mytable (
  mycolumn BIGINT NOT NULL,
  PRIMARY KEY(mycolumn),
  bar BIGINT REFERENCES foo (bar));

While we're at it, that big syntax literal should live in its own paragraph.

Dominant language
Rust
Stars
3.5k
Forks
774
Avg merge
3d 10h
Merged PRs (30d)
15

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/datafusion-sqlparser-rs

All issues in apache/datafusion-sqlparser-rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.