# function … does not exist / no such function

Source: https://sqlstreak.com/sql/errors/function-does-not-exist · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** The database has no function with that name for those arguments. Usually it's a function from another database (DATEDIFF is MySQL and SQL Server, strftime is SQLite, now() is PostgreSQL), or, in PostgreSQL, the right function with the wrong argument types.

## The exact messages

- PostgreSQL: `ERROR: function datediff(unknown, date) does not exist`
- SQLite: `no such function: DATEDIFF`

## How PostgreSQL prints it

```
ERROR:  function datediff(unknown, date) does not exist
LINE 1: SELECT id, DATEDIFF('2026-03-31', ordered_on) AS days_ago
                   ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
```

## Why it happens

### A function from another database

Date and text functions differ most between databases. `DATEDIFF`, `DATE_FORMAT`, `GETDATE()` and `ISNULL()` don't exist in PostgreSQL or SQLite; each has its own equivalent.

### The right name, the wrong argument types (PostgreSQL)

PostgreSQL matches functions by name and argument types. `ROUND(x, 2)` exists for `numeric`, not for `double precision`, so it reports `function round(double precision, integer) does not exist`. Cast the argument.

### A typo or a missing extension

Check the spelling. Some functions need an extension that isn't installed, which also looks like this error.

## The broken query

```sql
SELECT id, DATEDIFF('2026-03-31', ordered_on) AS days_ago
FROM orders;
```

## The fix

PostgreSQL:

```sql
SELECT id, DATE '2026-03-31' - ordered_on AS days_ago
FROM orders;
```

SQLite:

```sql
SELECT id,
  CAST(julianday('2026-03-31') - julianday(ordered_on) AS INTEGER) AS days_ago
FROM orders;
```

Each database has its own date arithmetic: PostgreSQL subtracts one date from another and gets days; SQLite turns dates into day numbers with `julianday()` first.

| id | days_ago |
| --- | --- |
| 1 | 30 |
| 2 | 30 |
| 3 | 28 |
| 4 | 27 |
| 5 | 26 |
| 6 | 26 |

(6 of 17 rows)
