Ecto's queries rely on macros to provide the powerful DSL that we use. That means that, whatever comes after from
, is not "regular" Elixir code, but a DSL which will eventually get transformed to SQL query. So, a caret there is not pin operator per se, and has nothing to do with pattern matching (although obviously it still can be called "pin operator" because people always forget words such as caret and ampersand and asterisk). It's just a convenient operator that Ecto's authors choose to be an "interpolation operator". Without it, the username
from your example would be taken literally, and inserted directly to the generated SQL (though Ecto is smart enough to see that that's not what you want so it spills an error).
Great question BTW, inspired me to read more about macros (newbie in FP here).