Error using to_char // to_timetamp

Posted by pepersview on Stack Overflow See other posts from Stack Overflow or by pepersview
Published on 2010-05-23T07:48:10Z Indexed on 2010/05/23 7:50 UTC
Read the original article Hit count: 217

Filed under:

Hello,

I have a database in PostgreSQL and I'm developing an application in PHP using this database. The problem is that when I execute the following query I get a nice result in phpPgAdmin but in my PHP application I get an error.

The query:

SELECT t.t_name, t.t_firstname
                        FROM teachers AS t
                        WHERE t.id_teacher IN (SELECT id_teacher FROM teacher_course AS tcourse
                                                            JOIN course_timetable AS coursetime
                                                            ON tcourse.course = coursetime.course
                                                            AND to_char(to_timestamp('2010-4-12', 'YYYY-MM-DD'),'FMD') = (coursetime.day +1))
                        AND t.id_teacher NOT IN (SELECT id_teacher FROM teachers_fill WHERE date = '2010-4-12')

                        ORDER BY t.t_name ASC

And this is the error in PHP

operator does not exist: text = integer (to_timestamp('', 'YYYY-MM-DD'),'FMD') =
 (courset... ^ HINT: No operator matches the given name and argument type(s). 
You might need to add explicit type casts.

The purpose to solve this error is to use the ORIGINAL query in php with :

$date = "2010"."-".$selected_month."-".$selected_day;

SELECT t.t_name, t.t_firstname
                        FROM teachers AS t
                        WHERE t.id_teacher IN (SELECT id_teacher FROM teacher_course AS tcourse
                                                            JOIN course_timetable AS coursetime
                                                            ON tcourse.course = coursetime.course
                                                            AND to_char(to_timestamp('$date', 'YYYY-MM-DD'),'FMD') = (coursetime.day +1))
                        AND t.id_teacher NOT IN (SELECT id_teacher FROM teachers_fill WHERE date = '$date')

                        ORDER BY t.t_name ASC

© Stack Overflow or respective owner

Related posts about postgresql