Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir/Ecto/Postgres试图从查询中获取整数,但却获取字符列表?_Elixir_Ecto - Fatal编程技术网

Elixir/Ecto/Postgres试图从查询中获取整数,但却获取字符列表?

Elixir/Ecto/Postgres试图从查询中获取整数,但却获取字符列表?,elixir,ecto,Elixir,Ecto,这似乎是世界上最简单的事情,但我正在尝试从一个EXTO查询返回一个整数: iex(10)> num = Polo.Repo.all(from n in Polo.Account.Number, select: max(n.account)) [debug] QUERY OK source="account_numbers" db=3.0ms queue=0.1ms SELECT max(a0."account") FROM "account_numbers" AS a0 [] [70241

这似乎是世界上最简单的事情,但我正在尝试从一个EXTO查询返回一个整数:

iex(10)> num = Polo.Repo.all(from n in Polo.Account.Number, select: max(n.account))
[debug] QUERY OK source="account_numbers" db=3.0ms queue=0.1ms
SELECT max(a0."account") FROM "account_numbers" AS a0 []
[7024184]

iex(11)> IO.inspect(num)
[7024184]
[7024184]

iex(12)> IO.puts(num)
** (ArgumentError) argument error
   (stdlib) :io.put_chars(:standard_io, :unicode, [[7024184], 10])

iex(12)> num + 1
** (ArithmeticError) bad argument in arithmetic expression
    :erlang.+([7024184], 1)
正确的数字实际上是7024184,但由于某些原因,它没有作为整数返回。它似乎是一个字符列表

任何帮助都将不胜感激


运行最新的Elixir 1.4.4

Repo.all
始终返回一个列表。由于您选择的是一个整数,因此会返回一个整数列表

如果只想获得一个值,可以使用
Repo.one

num = Polo.Repo.one(from n in Polo.Account.Number, select: max(n.account))
# num should be just the integer `7024184` now

Repo.all
始终返回一个列表。由于您选择的是一个整数,因此会返回一个整数列表

如果只想获得一个值,可以使用
Repo.one

num = Polo.Repo.one(from n in Polo.Account.Number, select: max(n.account))
# num should be just the integer `7024184` now

在长生不老药中,字符表只是一个整数列表。在长生不老药中,字符表只是一个整数列表。哇,太简单了!谢谢你的快速回复!哇,太简单了!谢谢你的快速回复!