[Dbix-class] How to specify intervals when creating/updating
entries in Postgresql db table using DBIX::CLASS
kakimoto at tpg.com.au
kakimoto at tpg.com.au
Fri Jul 3 01:42:28 GMT 2009
hi there
I have a Postgresql 8.3 db table, UserSubscriptions. Here's what it
looks like:
id integer
user_id text
subscriptions_id integer
name text
active_from timestamp with time zone
active_to timestamp with time zone
comments text
created_by character varying(12)
updated_by character varying(12)
created_on timestamp with time zone
updated_on timestamp with time zone
On activation of certain subscriptions, I would like to set the
active_from and active_to attributes.
Setting the active_from value to the current timestamp using NOW() is ok.
I am stuck with setting the value for active_to with " NOW() + interval
'3 months' " doesn't work.
I have an error below:
[START - error extract]
DBI Exception: DBD::Pg::st execute failed: ERROR:
INSERT INTO user_subscriptions ( active_from, active_to, created_by,
created_on, name, rea_agent_code, subscriptions_
id, updated_by, updated_on, user_id) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?,
? )" with ParamValues: 1='NOW()', 2='NOW() + interval '3 months'',
3='evomr', 4='2009-
07-03 01:11:08+0000', 5='Lucerne Apartments', 6='LUCRNW', 7='22',
8='admin_user_account', 9='2009-07-03 01:11:08+0000', 10='evomr'] at
/usr/local/lib/perl5/site_perl/5.8.9
/DBIx/Class/Schema.pm line 994
[END - error extract]
This is a snippet of my code:
[START - code snippet]
my %attributes = (
q{user_id} => $c->user->login_id(),
q{subscriptions_id} =>
$c->request->body_parameters->{'subscription_plan_id'},
q{name} => $c->request->body_parameters->{'name'},
q{created_by} => $c->user->login_id(),
q{updated_by} => $c->user->login_id(),
q{active_from} => q{NOW()},
q{active_to} => q{NOW() + interval '3 months'},
);
...
my $user_subscription = $c->model('myAppDB::UserSubscriptions')
->create(
\%attributes,
);
[END - code snippet]
If I were to do it on the postgresql interface, then it's ok.
I used something like:
UPDATE User_subscriptions SET Active_To = now() + interval '3 months'
where ID =4;
Any ideas?
thank you
K. akimoto
More information about the DBIx-Class
mailing list