简体   繁体   English

Rails -PG :: InvalidTextRepresentation:错误:格式不正确的数组文字

[英]Rails -PG::InvalidTextRepresentation: ERROR: malformed array literal

add_column :ssr_service_markets, :origin, :string, array: true, default: []

and when i want to 当我想

SSRService::Market.where(origin: "*", destination: "*").first

I have got 我有

PG::InvalidTextRepresentation: ERROR: malformed array literal: "*" LINE 1: ...service_markets" WHERE "ssr_service_markets"."origin" = '*' DETAIL: Array value must start with "{" or dimension information

How to fix it? 如何解决?

In Postgres, to check if an array contains given element, you can use @> array operator. 在Postgres中,要检查数组是否包含给定元素,可以使用@>数组运算符。

Read more: Array Operators 阅读更多: 数组运算符


:origin is an array field in your ssr_service_markets table, which means that it can contain multiple values. :originssr_service_markets表中的一个数组字段,这意味着它可以包含多个值。

In your example, assuming that destination is an array field as well, you could try to do the searching this way: 在您的示例中,假设destination也是数组字段,则可以尝试通过以下方式进行搜索:

Model.where(["origin @> ? AND destination @> ?", '{*}', '{*}')"])

Remember about using curly braces when working with array values . 记住在处理数组值时要使用花括号

To write an array value as a literal constant, enclose the element values within curly braces [...] 要将数组值写为文字常量,请将元素值括在花括号内[...]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ruby on Rails测试-ActiveRecord :: StatementInvalid:PG :: InvalidTextRepresentation:错误:格式不正确的数组文字: - Ruby on Rails Testing - ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: malformed array literal: 在Rails中使用Postgres UUID时,请避免PG :: InvalidTextRepresentation错误 - Avoid PG::InvalidTextRepresentation error when using Postgres UUID in Rails PG :: InvalidTextRepresentation:错误:整数的无效输入语法 - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer 导轨。 按数组过滤 Postgres 对象。 错误:格式错误的数组文字 - Rails. Filter Postgres objects by their Arrays. ERROR: malformed array literal PG :: InvalidTextRepresentation:错误:整数的无效输入语法:“ aaa” - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “aaa” heroku:PG :: InvalidTextRepresentation:错误:整数的无效输入语法:“” - heroku: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “” ActiveRecord::Enum - PG::InvalidTextRepresentation:错误:整数输入语法无效: - ActiveRecord::Enum - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: Friendly_id PG :: InvalidTextRepresentation:错误:整数的无效输入语法: - Friendly_id PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: PG :: InvalidTextRepresentation:ERROR:整数的输入语法无效:“M” - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “M” PostgreSQL:比较数组会导致“格式错误的数组文字”错误 - Postgresql: comparing arrays results in “malformed array literal” error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM