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

Naming Collision When Column Called "Timestamp". #1018

Closed
Measter opened this Issue Jul 11, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@Measter

Measter commented Jul 11, 2017

Setup

Versions

  • Rust: Stable, 1.18.0
  • Diesel: 0.14.1
  • Database: SQLite
  • Operating System Windows 10

Feature Flags

  • diesel: "sqlite"
  • diesel_codegen: "sqlite"

Problem Description

Trying to infer a table with a column called "Timestamp" causes a name collision.

What are you trying to accomplish?

I need to read an existing database, which has multiple tables with columns called "Timestamp". I cannot change the database schema.

What is the actual output?

error: `Timestamp` is ambiguous
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: `Timestamp` could refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `Timestamp` could also refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: consider adding an explicit import of `Timestamp` to disambiguate
  = note: this error originates in a macro outside of the current crate

error: `Timestamp` is ambiguous
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: `Timestamp` could refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `Timestamp` could also refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: consider adding an explicit import of `Timestamp` to disambiguate
  = note: this error originates in a macro outside of the current crate

error: `Timestamp` is ambiguous
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: `Timestamp` could refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `Timestamp` could also refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: consider adding an explicit import of `Timestamp` to disambiguate
  = note: this error originates in a macro outside of the current crate

error: `Timestamp` is ambiguous
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: `Timestamp` could refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `Timestamp` could also refer to the name imported here
 --> src\schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: consider adding an explicit import of `Timestamp` to disambiguate
  = note: this error originates in a macro outside of the current crate

Are you seeing any additional errors?

No.

Steps to reproduce

Create a table with a column labelled "Timestamp".

CREATE TABLE "test" ( `Timestamp` INTEGER, PRIMARY KEY(`Timestamp`) )

Checklist

  • [ X] I have already looked over the issue tracker for similar issues.
@killercup

This comment has been minimized.

Member

killercup commented Jul 11, 2017

Interesting case, and one I haven't seen in production so far! We've seen many column names that are also Rust keywords (like type), but a collision because the column name is also type name is a new one!

I'm fairly certain we know the right solution for this, though: Allowing you to rename the columns on the Rust side. This is tracked by #967.

I hope it's okay for me to close this issue (to continue discussion in #967); if not, or if I missed something, just let me know. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment