[Catalyst] Null values in DBIx::Class

Xavier Robin robin0 at etu.unige.ch
Thu Nov 23 15:52:09 GMT 2006


Hello,

I have the following table defined in a PostgreSQL database:

CREATE TABLE test_table (
  id      SERIAL PRIMARY KEY,
  column1 INTEGER REFERENCES test_table2,
  column2 INTEGER UNIQUE NOT NULL REFERENCES test_table3
);

I have set up MYAPPDB::TestTable with the unique key test_table_column2.
Now in my controller I do that:

$->model(MYAPPDB::TestTable)->update_or_create({
   'column1' => $value1,
   'column2' => $value2
}, {key => 'test_table_column2'}
);

If $value1 is null, I get the following error:

Caught exception in 
MYAPP::Controller::Root->test_action "DBIx::Class::ResultSet::update_or_create(): 
Error executing 'UPDATE test_table SET column1 = ? WHERE ( column2 = ? )': 
ERROR:  invalid input syntax for integer: "NULL""

I tried with $value1 = 'NULL', $value1 = '' or undef $value1, but none of them 
worked.

How can I enter a null value in a foreign key column?
Note: it works fine in PostgreSQL when I do UPDATE test_table SET column1 = 
NULL WHERE column2 = $value2.

Can you help me?

Thanks in advance !

Xavier



More information about the Catalyst mailing list