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

diesel::expression::dsl::now cannot be used with diesel::pg::types::sql_types::Timestamptz #685

Closed
andy128k opened this Issue Feb 12, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@andy128k

andy128k commented Feb 12, 2017

I'm trying to execute following query:

        diesel::update(session.filter(key.eq(new_session.key)))
            .set((
                data.eq(new_session.data),
                accessed.eq(now),
            ))
            .execute(&connection)
            .unwrap();

Here accessed is Timestamptz field.

It doesn't compile and I receive

expected struct `diesel::types::Timestamp`, found struct `diesel::types::Timestamptz`

As a workaround I copied-and-pasted now and redefined Expression

pub struct NowTz;

impl Expression for NowTz {
    type SqlType = Timestamptz;
}

...

but it would be nice to have built-in solution.

sgrif added a commit that referenced this issue Feb 12, 2017

Allow `now` to be used as a timestamptz
There are two things wrong with this PR, but I still think this is the
best short term solution.

The first and most glaringly obviously wrong thing about it is that the
type of `NOW()` **IS** `timestamptz`. However, since we currently have
that defined as a PG specific type, we can't set the type of the
expression properly. Timestamp with/without timezone is a thing in the
SQL standard, (it's just ignored by SQLite). I need to examine how MySQL
handles it and figure out how to promote it to a more general type.
However, I don't want to deal with that right now (and probably not
before 0.11). I do still want to fix this issue, so here we are.

We also have a more general problem of type equivalence that we need to
address. `Json` expressions can always be used where a `Jsonb` is
expected. `Text` with `VarChar` (though we've skirted that one by making
them type aliases). Again, this is a deeper problem that I don't
currently have a solution in mind for.

So in the short term, this gives us a way to punt on the problem for a
while. For the most common cases that crop up, we can write
`AsExpression` impls for those cases when we notice them.

Fixes #685.

sgrif added a commit that referenced this issue Feb 12, 2017

Allow `now` to be used as a timestamptz
There are two things wrong with this PR, but I still think this is the
best short term solution.

The first and most glaringly obviously wrong thing about it is that the
type of `NOW()` **IS** `timestamptz`. However, since we currently have
that defined as a PG specific type, we can't set the type of the
expression properly. Timestamp with/without timezone is a thing in the
SQL standard, (it's just ignored by SQLite). I need to examine how MySQL
handles it and figure out how to promote it to a more general type.
However, I don't want to deal with that right now (and probably not
before 0.11). I do still want to fix this issue, so here we are.

We also have a more general problem of type equivalence that we need to
address. `Json` expressions can always be used where a `Jsonb` is
expected. `Text` with `VarChar` (though we've skirted that one by making
them type aliases). Again, this is a deeper problem that I don't
currently have a solution in mind for.

So in the short term, this gives us a way to punt on the problem for a
while. For the most common cases that crop up, we can write
`AsExpression` impls for those cases when we notice them.

Fixes #685.

@sgrif sgrif closed this in #687 Feb 12, 2017

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