Difference between EXTRACT(year from timestamp) function and date_part('year', timestamp) in PostgreSQL

They are both the same.

In fact extract() gets re-written to date_part() - check the execution plan and you will see.

extract() complies with the SQL standard, date_part() is a Postgres specific query. As one gets converted to the other, there is absolutely no performance difference. If you prefer to write standard SQL, stick to extract()


I quote the answer from Postgresql.org

Blockquote The EXTRACT syntax ends up as a call to the internal date_part(...) function. If SQL-portability is not a concern, calling date_part() directly should be a bit quicker.

Reference Link

Tags:

Postgresql