Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MahmoudAdelAli's avatar

Undefined function: 7 ERROR: function timediff posgresql laravel

Hi , after i finished my app and every thing is okay now i deploy it on heroku but when i login with employee i got

SQLSTATE[42883]: Undefined function: 7 ERROR: function timediff(character varying, character varying) does not exist
LINE 1: select sum(time_to_sec(timediff(checkin, checkout))) as aggr...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. (SQL: select sum(time_to_sec(timediff(checkin, checkout))) as aggregate from "employee_attendances" where "employee_attendances"."employee_id" = 1 and "employee_attendances"."employee_id" is not null and extract(day from "created_at") = 14 and "checkout" is not null)

the database is posgresql and i think the problem is here

    return CarbonInterval::seconds($this->attendances_working_hours->sum(DB::raw("time_to_sec(timediff(checkin, checkout))")))->cascade()->forHumans();

any help ?

0 likes
15 replies
Sinnbeck's avatar

Can you point to the docs for that function? I cannot seem to find it anywhere. I can only find datediff()

1 like
MahmoudAdelAli's avatar

@Sinnbeck

https://www.tutorialspoint.com/mysql/mysql_date_time_functions_timediff.htm
https://www.w3schools.com/sql/func_mysql_timediff.asp
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
Sinnbeck's avatar

@MahmoudAdelAli mysql? But you said you were running postgres? Are you running mysql locally and postgres on production?

1 like
Sinnbeck's avatar

@MahmoudAdelAli Then you cannot use raw expressions. They are not the same database type.. So either switch to postgres localla and rewrite the query, or switch to mysql on production

1 like
MahmoudAdelAli's avatar

@Sinnbeck heroku doesn't support mysql just posgresql , i tried

    return CarbonInterval::seconds($this->attendances_working_hours->sum(DB::raw("time_to_sec( date_part('hour','" . $this->attributes['checkin'] . "'::time -  '" . $this->attributes['checkout'] . "'::time)  *60+ date_part  ('minute', '" . $this->attributes['checkin'] . "'::time -'" . $this->attributes['checkout'] . "'::time))")))->cascade()->forHumans();

from search but i got

Undefined array key "checkin"
Sinnbeck's avatar

@MahmoudAdelAli Thats a php error. It means that $this->attributes['checkin'] does not have a key named checkin

1 like
MahmoudAdelAli's avatar

@Sinnbeck yes i know cause the check in relation to employee and he have many , and know i don't understand how i can solve this problem with postgre :D

Sinnbeck's avatar

@MahmoudAdelAli Well sadly I don't know postgres syntax, but I can suggest installing it locally so you can make sure your code works before deployment

Tray2's avatar

Postgres and MySQL are pretty similar but the have different SQL dialect, so some things that work in MySQL will not work on PostgreSQL and vice versa.

You really should develop using the same or as close to the same setup as you have in production.

1 like
Tray2's avatar

@MahmoudAdelAli I have both on my local dev, but I mostly use MySQL, the PostgreSQL is for testing stuff out.

1 like

Please or to participate in this conversation.