{"action":"closed","issue":{"url":"https://api.github.com/repos/cockroachdb/cockroach/issues/3294","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/3294/labels{/name}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/3294/comments","events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/3294/events","html_url":"https://github.com/cockroachdb/cockroach/issues/3294","id":120040647,"number":3294,"title":"sql: LEAST and GREATEST can panic the lib/pq client","user":{"login":"mjibson","id":41181,"avatar_url":"https://avatars.githubusercontent.com/u/41181?v=3","gravatar_id":"","url":"https://api.github.com/users/mjibson","html_url":"https://github.com/mjibson","followers_url":"https://api.github.com/users/mjibson/followers","following_url":"https://api.github.com/users/mjibson/following{/other_user}","gists_url":"https://api.github.com/users/mjibson/gists{/gist_id}","starred_url":"https://api.github.com/users/mjibson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjibson/subscriptions","organizations_url":"https://api.github.com/users/mjibson/orgs","repos_url":"https://api.github.com/users/mjibson/repos","events_url":"https://api.github.com/users/mjibson/events{/privacy}","received_events_url":"https://api.github.com/users/mjibson/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-02T21:33:31Z","updated_at":"2015-12-03T19:04:38Z","closed_at":"2015-12-03T19:04:38Z","body":"The following program will panic the postgres driver. This is because the result of the select is a float, but the cockroach implementation hints to pq that it will return an int (since it is the first argument in the function, and cockroach finds the return type by executing the function with zero values).\r\n\r\nPostgres converts all arguments of LEAST and GREATEST to the same type, and returns that type: http://www.postgresql.org/docs/8.3/static/functions-conditional.html#AEN14539\r\n\r\nI think instead of mirroring the postgres implementation, we should error during parse if the arguments to LEAST and GREATEST are not all of the same type. We can improve this later if we want, but it's good enough for now.\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"database/sql\"\r\n\t\"fmt\"\r\n\t\"log\"\r\n\r\n\t\"github.com/cockroachdb/cockroach/security\"\r\n\t_ \"github.com/lib/pq\"\r\n)\r\n\r\nfunc main() {\r\n\tdb, err := sql.Open(\"postgres\", fmt.Sprintf(\"sslmode=disable user=%s host=%s port=%s\", security.RootUser, \"127.0.1.1\", \"40342\"))\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\r\n\tvar v float64\r\n\terr = db.QueryRow(\"SELECT GREATEST(1, 2.0);\").Scan(&v)\r\n\tfmt.Println(err, v)\r\n}\r\n```"}}