Welcome Guest, Not a member yet? Register   Sign In
Active record and PostgreSQL operator in where function error
#1

[eluser]acesfull9[/eluser]
The following code:
Code:
$this->db->select("events.*");
$this->db->from('events');
$this->db->where("event_date>=", $start_date);
$this->db->where("event_date<=", $end_date);
Generates the following query:
Code:
SELECT "events"."*" FROM "events"
WHERE "event_date>=" '2008-12-26' AND "event_date<=" '2009-01-05'
Which errors out because of the operators being included within the double quotes. The following query is what should be generated:
Code:
SELECT "events"."*" FROM "events"
WHERE "event_date">= '2008-12-26' AND "event_date"<= '2009-01-05'

I have been looking at the postgre_driver and the active record class for a while now and am not sure where this would need to be fixed. It works fine in MySQL (I am converting an application from MySQL to PostgreSQL).

Any help would be greatly appreciated!

Oh and I am using Codeigniter 1.7.0 and PostreSQL 8.3.5.
#2

[eluser]acesfull9[/eluser]
Ok so I figured it out. Not sure whether this should be considered a bug or not(probably not). If you put a space in between the column name and the operator, it works fine.

This:
Code:
$this->db->where("event_date >=", $start_date);
$this->db->where("event_date <=", $end_date);
Instead of this:
Code:
$this->db->where("event_date>=", $start_date);
$this->db->where("event_date<=", $end_date);

Everything seems to work fine. Looking at the user guide a little closer, there are also spaces between the column and the operator. Should have payed closer attention. Hopefully this post saves some people some time.




Theme © iAndrew 2016 - Forum software by © MyBB