sqlstreak

SQL functions: PostgreSQL and SQLite, tested

The functions where PostgreSQL and SQLite differ most. Each page has the syntax in both, examples, and a table of edge cases run on both engines, so you see what really comes back.

FunctionWhat it doesPostgreSQLSQLite
strftimestrftime(format, date, modifiers…) turns a date or time into text in the format you give: strftime('%Y-%m', '2026-03-15') returns '2026-03'.No: use to_char() or EXTRACT()Yes, built in
datedate(value, modifier, …) returns a date as 'YYYY-MM-DD' text after applying the modifiers in order: date('2026-03-15', '+7 days') is '2026-03-22'.No date() function: use date arithmetic and date_truncYes, built in
juliandayjulianday(date) returns the date as a Julian day number, a decimal count of days, so julianday(d2) - julianday(d1) is the number of days between two dates.No: subtract dates; to_char(d, 'J') gives a whole Julian day numberYes, built in
string_agg / group_concatstring_agg(value, separator) is an aggregate that joins the values of a group into one string: string_agg(name, ', ' ORDER BY name).string_agg: yes. group_concat: noBoth (string_agg since 3.44)
substrsubstr(text, start, length) returns part of a string, counting from 1: substr('Biscuit', 1, 3) is 'Bis'.YesYes
instr / strpos / positionSQLite's instr(text, part) returns the position of the first occurrence of part, counting from 1, or 0 if it isn't there.strpos and POSITION: yes. instr: noinstr: yes. strpos, POSITION: no
printf / formatSQLite's printf(format, values…) (also called format()) fills placeholders C-style: printf('%.2f', 3.14159) is '3.14'.format: yes (text only). printf: noprintf and format: yes
COALESCE / IFNULLCOALESCE(a, b, …) returns the first argument that isn't NULL: COALESCE(breed, 'mixed') shows 'mixed' where the breed is missing.COALESCE: yes. IFNULL: noBoth
NULLIFNULLIF(a, b) returns NULL when a equals b, and a otherwise.YesYes
CASTCAST(value AS type) converts a value to another type: CAST('42' AS INTEGER) is the number 42.Yes, plus the :: shorthandYes (no ::)
ROUNDROUND(x, n) rounds x to n decimal places (to a whole number without n): ROUND(13.456, 2) is 13.46.Yes (with digits only for numeric)Yes
REPLACEREPLACE(text, from, to) returns the text with every occurrence of from swapped for to: REPLACE('555-0101', '-', '') is '5550101'.YesYes