The PostgreSQL date functions documentation contains the following example:

date '2001-09-28' + integer '7'

Why does it consist of converting a string to an integer? Why not phrase it like this:

date '2001-09-28' + 7

Is there some tangible reason why integer '7' is preferable to plain old 7?

| improve this question | | | | |
  • The table is ancient, it's been maintained in essentially the same form since 7.2. It needs to be broken up into right and left operand types, like the newer JSON table. Most of the Pg operator stuff is horrible unstandardized with wide variations but awesomely detailed and easy to understand. My assumption: prior to having right/left operand types on tables, they used this to show the type that the operator was expecting and just overshot on clarity and explicitness in that dynamic. – Evan Carroll Jun 9 '17 at 15:15
  • @EvanCarroll probably just trying to visually differentiate between "integer" and "interval". – Jacob H Jun 9 '17 at 19:30

Interesting question, and I don't know the answer. My best guess is that all the other examples use the same way of casting, and someone thought it is better having it consistent. If you are pissed off irked by this, you can scroll to the bottom of the page and send a complaint using the form linked there.

| improve this answer | | | | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.