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

infer_schema!() with postgres Timestamptz fails #402

Closed
astraw opened this Issue Aug 13, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@astraw

astraw commented Aug 13, 2016

Using infer_schema!() macro on a postgres database with Timestamptz fails with the following error:

rc/lib.rs:1:1: 1:1 error: type name `Timestamptz` is undefined or not in scope [E0412]
src/lib.rs:1 #![feature(custom_derive, custom_attribute, plugin)]
             ^
<diesel macros>:5:1: 5:71 note: in this expansion of table_body! (defined in <diesel macros>)
src/schema.rs:1:1: 1:40 note: in this expansion of table! (defined in <diesel macros>)
src/schema.rs:1:1: 1:40 note: in this expansion of infer_schema! (defined in src/lib.rs)
src/lib.rs:8:1: 8:23 note: in this expansion of include!
src/lib.rs:1:1: 1:1 help: run `rustc --explain E0412` to see a detailed explanation
src/lib.rs:1:1: 1:1 help: no candidates by the name of `Timestamptz` found in your project; maybe you misspelled the name or forgot to import an external crate?
src/lib.rs:1:1: 1:1 error: type name `Timestamptz` is undefined or not in scope [E0412]
src/lib.rs:1 #![feature(custom_derive, custom_attribute, plugin)]
             ^
<diesel macros>:45:5: 45:51 note: in this expansion of column! (defined in <diesel macros>)
<diesel macros>:5:1: 5:71 note: in this expansion of table_body! (defined in <diesel macros>)
src/schema.rs:1:1: 1:40 note: in this expansion of table! (defined in <diesel macros>)
src/schema.rs:1:1: 1:40 note: in this expansion of infer_schema! (defined in src/lib.rs)
src/lib.rs:8:1: 8:23 note: in this expansion of include!
src/lib.rs:1:1: 1:1 help: run `rustc --explain E0412` to see a detailed explanation
src/lib.rs:1:1: 1:1 help: no candidates by the name of `Timestamptz` found in your project; maybe you misspelled the name or forgot to import an external crate?
error: aborting due to 2 previous errors
error: Could not compile `diesel_demo`.

An example of such can be found at https://github.com/strawlab/diesel_demo/tree/timestamptz . The specific issue is uncovered by adding this to the database

CREATE TABLE mytable (
  id SERIAL PRIMARY KEY,
  when_utc TIMESTAMPTZ
);

sgrif added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
This adds support for the `timestamp with time zone` type. This is part
of the SQL standard, but not supported explicitly by SQLite as far as I
can tell. As such I've made it a PG specific type for now.

timestamp with time zone does not actually mean that a time zone is
stored. It instead means that when dealing with strings, Postgres will
no longer ignore the time zone portion. It will convert the time zone to
UTC for storage. When transmitted as text, it will be converted to the
database's local time zone. When transmitted as binary, it will be sent
as UTC.

As such, I've provided `ToSql` implementations for basically all flavors
of `DateTime`, but I've only provided a `FromSql` implementation for
`DateTime<UTC>` and `NaiveDateTime`. I have not provided any
implementation for `std::time::SystemTime`, as it implies local time
zone for the machine and we do not have the tools to handle the
conversion in the standard library.

Fixes #106.
Fixes #295.
Fixes #402.

sgrif added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
This adds support for the `timestamp with time zone` type. This is part
of the SQL standard, but not supported explicitly by SQLite as far as I
can tell. As such I've made it a PG specific type for now.

timestamp with time zone does not actually mean that a time zone is
stored. It instead means that when dealing with strings, Postgres will
no longer ignore the time zone portion. It will convert the time zone to
UTC for storage. When transmitted as text, it will be converted to the
database's local time zone. When transmitted as binary, it will be sent
as UTC.

As such, I've provided `ToSql` implementations for basically all flavors
of `DateTime`, but I've only provided a `FromSql` implementation for
`DateTime<UTC>` and `NaiveDateTime`. I have not provided any
implementation for `std::time::SystemTime`, as it implies local time
zone for the machine and we do not have the tools to handle the
conversion in the standard library.

Fixes #106.
Fixes #295.
Fixes #402.

sgrif added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
This adds support for the `timestamp with time zone` type. This is part
of the SQL standard, but not supported explicitly by SQLite as far as I
can tell. As such I've made it a PG specific type for now.

timestamp with time zone does not actually mean that a time zone is
stored. It instead means that when dealing with strings, Postgres will
no longer ignore the time zone portion. It will convert the time zone to
UTC for storage. When transmitted as text, it will be converted to the
database's local time zone. When transmitted as binary, it will be sent
as UTC.

As such, I've provided `ToSql` implementations for basically all flavors
of `DateTime`, but I've only provided a `FromSql` implementation for
`DateTime<UTC>` and `NaiveDateTime`. I have not provided any
implementation for `std::time::SystemTime`, as it implies local time
zone for the machine and we do not have the tools to handle the
conversion in the standard library.

Fixes #106.
Fixes #295.
Fixes #402.

sgrif added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
This adds support for the `timestamp with time zone` type. This is part
of the SQL standard, but not supported explicitly by SQLite as far as I
can tell. As such I've made it a PG specific type for now.

timestamp with time zone does not actually mean that a time zone is
stored. It instead means that when dealing with strings, Postgres will
no longer ignore the time zone portion. It will convert the time zone to
UTC for storage. When transmitted as text, it will be converted to the
database's local time zone. When transmitted as binary, it will be sent
as UTC.

As such, I've provided `ToSql` implementations for basically all flavors
of `DateTime`, but I've only provided a `FromSql` implementation for
`DateTime<UTC>` and `NaiveDateTime`. I have not provided any
implementation for `std::time::SystemTime`, as it implies local time
zone for the machine and we do not have the tools to handle the
conversion in the standard library.

Fixes #106.
Fixes #295.
Fixes #402.

@sgrif sgrif closed this in #409 Aug 18, 2016

@MarkJr94

This comment has been minimized.

MarkJr94 commented Sep 11, 2016

I'm still having this issue, with diesel version 0.7.1 from crates.io. Am I doing something wrong?

@sgrif

This comment has been minimized.

Member

sgrif commented Sep 11, 2016

0.7.1 doesn't support timestamptz. It will be in 0.8

@MarkJr94

This comment has been minimized.

MarkJr94 commented Sep 11, 2016

Ah, thanks for the clarification, and sorry for the confusion.

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