Data migration of date constant

A simple question: what is the correct way to input a fixed string as a
datetime field within a rails data migration?

I tried this:


:record_effective_from => ‘20020731000000’,

And got this:

== AddEntityTestData: migrating

rake aborted!
RuntimeError: ERROR C42804 Mcolumn “record_effective_from” is of
type timestamp without time zone but expression is of type bigint HYou
will need to rewrite or cast the expression.

Soooo… how do I rewrite or recast this to work?

Regards,

James B. wrote:

Soooo… how do I rewrite or recast this to work?

Regards,

Enclose the date in single or double quotes. Ok, I got that to work.
Next question.

I have to load historical data and some of the dates are pre-1900. How
do I get rails / ruby / postgresql to handle this. As of now when I do
this:


:record_effective_from => ‘<%= DateTime.parse(“18920801000000”)
%>’,

or this:


:record_effective_from => ‘18920801000000’,

both yield this on the database:

1901-12-13 15:45:52

The OS is CentOS-4.4 with ruby 1.8.4 (2005-12-24) [i386-linux] and rails
(1.1.6.5848) (1.2RC1)

James B. wrote:

The OS is CentOS-4.4 with ruby 1.8.4 (2005-12-24) [i386-linux] and rails
(1.1.6.5848) (1.2RC1) and postgres-pr (0.4.0)

I have another problem with data migrations. I have added two fields to
the subject table that are called “changed_on” and “created-on”
repectively. These are supposed to default to the current time according
to my understanding of the Rails conventions and therefore I have not
named them in the data migration. However, when I run rake db:migrate I
get this:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== CreateEntities: migrating

– create_table(:entities)
rake aborted!
RuntimeError: ERROR C0A000 Mdate/time value “current” is no longer
supported Fdatetime.c L1369 RDecodeDateTime: CREATE TABLE
entities (“id” serial primary key, “entity_ident” bigint NOT NULL,
“entity_name” character varying(40) NOT NULL, “entity_legal_style”
character varying(255) NOT NULL, “entity_type” character varying(4) NOT
NULL, “effective_from” timestamp NOT NULL, “superceded_after” timestamp,
“created_by” character varying(255) NOT NULL, “created_on” timestamp
DEFAULT ‘CURRENT_TIMESTAMP’, “changed_by” character varying(255) NOT
NULL, “changed_on” timestamp DEFAULT ‘CURRENT_TIMESTAMP’)
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/connection_adapters/abstract_adapter.rb:128:in
log' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/connection_adapters/postgresql_adapter.rb:152:inexecute’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/connection_adapters/abstract/schema_statements.rb:104:in
create_table' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:275:inmethod_missing’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:259:in
say_with_time' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:259:in
say_with_time' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:273:inmethod_missing’
./db/migrate//001_create_entities.rb:3:in real_up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:212:inmigrate’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:212:inmigrate’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:335:in
migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:330:inmigrate’
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:297:in
up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:288:inmigrate’
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6.5848/lib/tasks/databases.rake:4
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:inexecute’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in invoke' /usr/lib/ruby/1.8/thread.rb:135:insynchronize’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:inrun’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run’
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7
/usr/bin/rake:18

Does this mean that the adapter I am using is broken or is something
else amiss?

Regards,

Further to my last post, I replace postgres-pr with ruby-postgres and
tried again. the error now says:

rake aborted!
PGError: ERROR: date/time value “current” is no longer supported
: CREATE TABLE entities (“id” serial primary key, “entity_ident” bigint
NOT NULL, “entity_name” character varying(40) NOT NULL,
“entity_legal_style” character varying(255) NOT NULL, “entity_type”
character varying(4) NOT NULL, “effective_from” timestamp NOT NULL,
“superceded_after” timestamp, “created_by” character varying(255) NOT
NULL, “created_on” timestamp DEFAULT ‘CURRENT_TIMESTAMP’, “changed_by”
character varying(255) NOT NULL, “changed_on” timestamp DEFAULT
‘CURRENT_TIMESTAMP’)

This looks to me like it is a PostgreSQL issue but what is providing
Postgres with the date/time value of “current” (which was depreciated as
of PostgreSQl 7.2)