Skip to content

Cast into arrays (postgreSQL) #86

@fdutey

Description

@fdutey

Hi,

I couldn't find a solution to cast array types with arel extensions. According to the source code, only "raw" types are allowed but not things like int[].

Is there a workaround?
Thanks

Edit: my (very poor) workaround looks like this

table = scope.arel_table
 version = table[:version]

 split_version = Arel::Nodes::NamedFunction.new(
   'string_to_array', [version, Arel::Nodes::Quoted.new('.')]
)

# FIXME poor typecasting
cast = Arel.sql("#{split_version.to_sql}::int[]")

it works but im open to any "less ugly" solution because this one is just dirty as hell

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions