skip to Main Content

Starting from question : [https://stackoverflow.com/questions/78580133/which-query-is-executed-when-var-dumppg-fetch-allpg-query-paramsdb-select][1] and the last answer to it naturally arises the question what is the result of "select cast(2.000 as varchar);" ( don’t execute it before answering on your own). Where in the docs is it explained ?

To me the result is unexpected !!!

Answer without executing the statement, so we can check what is the "feeling" of people!

2

Answers


  1. From the manual:

    The CAST syntax conforms to SQL; the syntax with :: is historical
    PostgreSQL usage.

    Login or Signup to reply.
  2. It’s a postgres-style of casting, and it is mentioned in their docs:

    https://www.postgresql.org/docs/7.3/sql-syntax.html

    Without executing the query you posted, I’d expect the double 2.000 to be converted to a string… which has serious implications because "2.000" > "10" === true.

    EDIT: the above link points to an old version of postgres, but it’s still valid and it is what came up when I did a quick google search. Here is the link to the latest docs, the same syntax is still documented:

    https://www.postgresql.org/docs/current/sql-expressions.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search