Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
sqlite "timestamp with time zone" returns String objects
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
blambeau  
View profile  
 More options Aug 3 2012, 11:26 am
From: blambeau <blamb...@gmail.com>
Date: Fri, 3 Aug 2012 08:26:09 -0700 (PDT)
Local: Fri, Aug 3 2012 11:26 am
Subject: sqlite "timestamp with time zone" returns String objects

Hi Jeremy,

I'm not sure whether this is a bug, or if I use Sequel/SQlite in a strange
way. Anyway, the code below shows the issue I'm encountering and the way
I've found to fix it... Is there something I get wrong?

require 'sequel'
db = Sequel.sqlite
db.use_timestamp_timezones=true  # seen in another thread, does not change
anything

db.create_table(:test){
  primary_key :id
  column :latest_change, "timestamp with time zone", :default=>"now()".lit,
:null=>false

}

db[:test].insert(:latest_change => Time.now)

puts db[:test].first.inspect
# => {:id=>1, :latest_change=>"2012-08-03 17:19:23.294658"}

puts db[:test].first[:latest_change].class
# => String

# Explicit proc resolves the problem for me:
db.conversion_procs['timestamp with time zone'] =
db.method(:to_application_timestamp)
puts db[:test].first[:latest_change].class
# => Time


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Aug 3 2012, 11:43 am
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Fri, 3 Aug 2012 08:43:06 -0700 (PDT)
Local: Fri, Aug 3 2012 11:43 am
Subject: Re: sqlite "timestamp with time zone" returns String objects

On Friday, August 3, 2012 8:26:09 AM UTC-7, blambeau wrote:

> Hi Jeremy,

> I'm not sure whether this is a bug, or if I use Sequel/SQlite in a strange
> way. Anyway, the code below shows the issue I'm encountering and the way
> I've found to fix it... Is there something I get wrong?

> require 'sequel'
> db = Sequel.sqlite
> db.use_timestamp_timezones=true  # seen in another thread, does not change
> anything

This is the current default, so it shouldn't change anything. I am planning
to switch the default to false in the next major version, since I think
using timezones in timestamps does not work with the SQLite built-in
date/time functions.

db.create_table(:test){

>   primary_key :id
>   column :latest_change, "timestamp with time zone",
> :default=>"now()".lit, :null=>false
> }
> db[:test].insert(:latest_change => Time.now)

This is because "timestamp with time zone" is not recognized by Sequel's
sqlite adapter as a timestamp type, only "datetime" and "timestamp" are
recognized as such.  SQLite doesn't support a native timestamp type, so I'm
not sure why you are choosing to use "timestamp with time zone".  The
Sequel way to do what you want is:

db.create_table(:test){
  primary_key :id
  Time :latest_change, :default=>"now()".lit, :null=>false

}
> # Explicit proc resolves the problem for me:
> db.conversion_procs['timestamp with time zone'] =
> db.method(:to_application_timestamp)
> puts db[:test].first[:latest_change].class
> # => Time

If you really must use "timestamp with time zone" as your type, that's how
you are going to have to handle it.  I am not adding support for other
timestamp type names to the sqlite adapter (what's next, "timestamp without
time zone"?).

Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
blambeau  
View profile  
 More options Aug 3 2012, 12:43 pm
From: blambeau <blamb...@gmail.com>
Date: Fri, 3 Aug 2012 09:43:28 -0700 (PDT)
Local: Fri, Aug 3 2012 12:43 pm
Subject: Re: sqlite "timestamp with time zone" returns String objects

Thanks for your answer.

Actually, the reason I'm facing this issue is that I work with sqlite for
my tests, but the sqlite database is built with a schema dump from a legacy
database in postgresql.

The fact is that I'm forced to use "sequel -D" for now because the current
timestamp default value (:default=>"now()".lit)is not inferred by "sequel
-d".

Anyway, thanks again!
B


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Aug 3 2012, 1:36 pm
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Fri, 3 Aug 2012 10:36:23 -0700 (PDT)
Local: Fri, Aug 3 2012 1:36 pm
Subject: Re: sqlite "timestamp with time zone" returns String objects

On Friday, August 3, 2012 9:43:28 AM UTC-7, blambeau wrote:

> Thanks for your answer.

> Actually, the reason I'm facing this issue is that I work with sqlite for
> my tests, but the sqlite database is built with a schema dump from a legacy
> database in postgresql.

> The fact is that I'm forced to use "sequel -D" for now because the current
> timestamp default value (:default=>"now()".lit)is not inferred by "sequel
> -d".

I always recommend testing using the same database type you are using in
production, as it avoids a lot of problems.

Still, the root cause of your problem is that Sequel doesn't translate
'now()' to a generic ruby value.  It would be helpful if that were
translated to Sequel::CURRENT_TIMESTAMP when -d is used.  I've added that
to my todo list, it should hopefully make it into the next version.

Thanks,
Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy Evans  
View profile  
 More options Aug 14 2012, 3:20 pm
From: Jeremy Evans <jeremyeva...@gmail.com>
Date: Tue, 14 Aug 2012 12:20:43 -0700 (PDT)
Local: Tues, Aug 14 2012 3:20 pm
Subject: Re: sqlite "timestamp with time zone" returns String objects

On Friday, August 3, 2012 10:36:23 AM UTC-7, Jeremy Evans wrote:

> Still, the root cause of your problem is that Sequel doesn't translate
> 'now()' to a generic ruby value.  It would be helpful if that were
> translated to Sequel::CURRENT_TIMESTAMP when -d is used.  I've added that
> to my todo list, it should hopefully make it into the next version.

This should be fixed now:
https://github.com/jeremyevans/sequel/commit/48bcf889170072bc31636978...

Jeremy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »