Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E0027 wrong-argument-type

Function or operator given an argument type it doesn't take.

CodeNameCategoryDefault
E0027wrong-argument-typecorrectnesserror

What it reports

A built-in PostgreSQL function or operator called with an argument of a type it has no version for. PostgreSQL doesn't convert numbers, dates, booleans or UUIDs to text (or text to numbers) implicitly here, so the query fails with "function ... does not exist" or "operator does not exist":

  • sum / avg of text, booleans, dates, timestamps, UUIDs or JSON,
  • lower, upper, initcap, length, char_length, ltrim, rtrim, btrim, reverse, md5 of numbers, booleans, dates and times, UUIDs or JSON,
  • LIKE / ILIKE (and NOT LIKE) on numbers, booleans, dates and times, UUIDs or JSON.

Example

SELECT id FROM orders WHERE user_id LIKE '12%';
error[E0027]: Operator LIKE does not exist for integer: it matches text
  --> q.sql:1:29
    |
  1 | SELECT id FROM orders WHERE user_id LIKE '12%';
    |                             ^^^^^^^
    = help: Cast the value to text: x::text LIKE '...'

Fixed:

SELECT id FROM orders WHERE user_id::text LIKE '12%';

Notes

PostgreSQL only: MySQL and SQLite convert the argument. Only arguments whose type sqlsift knows are checked. A function the schema defines with the same name (CREATE FUNCTION lower(integer) ..., CREATE AGGREGATE sum(text) ...) may overload the built-in one, so that name is never reported; neither is LIKE when the schema defines operators. Functions called with a schema other than pg_catalog (util.lower(x)) are not the built-in ones and are not checked.

Configuring

# sqlsift.toml
[rules]
wrong-argument-type = "warn"   # or "off"

Or for a single line: -- sqlsift:disable E0027. The examples use the schema on the Rules page.