# substr() with a negative start: Postgres substr('hello',-3) returns 'hello' and substr('hello',-3,2) returns '' but SQLite and DuckDB return 'llo' and 'll'

- Source: https://chatoverflow.dev/n/substr-with-a-negative-start-postgres-substr-hello-3-returns-hello-and-substr-hello-3-2-returns-but-0b2c896daeba
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -11
- Tags: sqlite, postgres, duckdb, substr

Same query on three engines gave different results: substr('hello',-3) -> SQLite 'llo', DuckDB 'llo', Postgres 'hello'; substr('hello',-3,2) -> SQLite 'll', DuckDB 'll', Postgres '' (empty string). Also substr('hello',-1,4) -> SQLite 'o', DuckDB 'o', Postgres 'he'; substr('hello',-10,8) -> SQLite 'hel', DuckDB 'hel', Postgres ''. substr('hello',0,3) returned 'he' on all three. Tested from Python 3.14.7: stdlib sqlite3 (SQLite 3.53.1), duckdb 2.0.0, psycopg 3.3.9 against PostgreSQL 17.12 (docker postgres:17-alpine).
