# instr(), strpos() and POSITION(): find text in a string

Source: https://sqlstreak.com/sql/functions/instr · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** SQLite's `instr(text, part)` returns the position of the first occurrence of `part`, counting from 1, or 0 if it isn't there. PostgreSQL spells it `strpos(text, part)` or the standard `POSITION(part IN text)`, and has no instr.

## Syntax

- PostgreSQL: `strpos(text, part)  /  POSITION(part IN text)` (strpos and POSITION: yes. instr: no)
- SQLite: `instr(text, part)` (instr: yes. strpos, POSITION: no)

## Examples

### Where the @ is in each email

PostgreSQL:

```sql
SELECT LOWER(TRIM(email)) AS email, strpos(LOWER(TRIM(email)), '@') AS at_position
FROM adoption_requests
ORDER BY id
LIMIT 5;
```

SQLite:

```sql
SELECT LOWER(TRIM(email)) AS email, instr(LOWER(TRIM(email)), '@') AS at_position
FROM adoption_requests
ORDER BY id
LIMIT 5;
```

Result (both engines):

| email | at_position |
| --- | --- |
| ana@mail.com | 4 |
| ben@mail.com | 4 |
| ana@mail.com | 4 |
| cara@mail.com | 5 |
| dev@mail.com | 4 |

### Names that contain a space

Greater than 0 means found, a handy alternative to LIKE '% %'.

PostgreSQL:

```sql
SELECT name FROM menu_items
WHERE strpos(name, ' ') > 0
ORDER BY name;
```

SQLite:

```sql
SELECT name FROM menu_items
WHERE instr(name, ' ') > 0
ORDER BY name;
```

Result (both engines):

| name |
| --- |
| BBQ Meteor |
| Caesar Salad |
| Four Cheese Orbit |
| Garlic Knots |
| Lemon Soda |
| Pepperoni Rocket |
| Veggie Nebula |

### With substr: the domain after the @

PostgreSQL:

```sql
SELECT DISTINCT substr(LOWER(TRIM(email)), strpos(LOWER(TRIM(email)), '@') + 1) AS domain
FROM adoption_requests;
```

SQLite:

```sql
SELECT DISTINCT substr(LOWER(TRIM(email)), instr(LOWER(TRIM(email)), '@') + 1) AS domain
FROM adoption_requests;
```

Result (both engines):

| domain |
| --- |
| mail.com |

## Edge cases, measured on both engines

| Case | PostgreSQL | SQLite |
| --- | --- | --- |
| Found | 4 | 4 |
| Not found | 0 | 0 |
| The first of several | 2 | 2 |
| Case matters | 0 | 0 |
| The standard POSITION syntax | 4 | error: no such table: Biscuit |
| An empty search text | 1 | 1 |
| NULL | NULL | NULL |

## Common mistakes

- Using instr in PostgreSQL or strpos in SQLite: each has only its own name (POSITION works in PostgreSQL only, as the matrix shows).
- Forgetting that 0 means “not found”: `substr(x, instr(x, '@') + 1)` returns the whole string when there's no @.
- Expecting a case-insensitive search: wrap both sides in LOWER().
