Assuming we have two tables:
contacts table having columns: id and nameconversations table having columns: id and contact_id (FK to contacts.id)The following two queries return the same data:
SELECT contacts.name, contacts.id, conversations.id FROM contacts INNER JOIN conversations ON contacts.id = conversations.contact_id;
and
SELECT contacts.name, contacts.id, conversations.id FROM contacts INNER JOIN conversations ON id(contacts) = contact_id(conversations);
For a purely theoretical reason, I want to learn more about the second (more functional) version. What is this syntax called and where can I learn more? Is this syntax in the SQL standard or just PostgreSQL? Is it performant? Why is it not used more widely?
"Functional notation" is an extension to the SQL standard and performance is identical to the standard "attribute notation" (a.k.a. "dot notation").
There are subtle differences how names are resolved. Like: column names take precedence over functions taking the composite type in attribute notation.
Attribute notation only works for functions taking a single parameter. So that's a limited alternative, and the canonical way is to use functional notation for functions (hence the name).
On the other hand, attribute notation is simply shorter (one dot versus two parens), more portable (complies to the standard) and generally the canonical way to table-qualify columns.
Find details in the manual.
Related:
Functional notation is terribly obsolete - it is an artifact from NON SQL era.
Don't use it in production projects. It has no impact on performance - the differences are solved on the parser and analyzer levels, but it does not make any sense with respect to the SQL standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With