Faveod/arel-extensions

Just adding this gem breaks PG gem

Opened this issue · 2 comments

ActiveRecord::StatementInvalid (PG::UndefinedObject: ERROR:  type "VARCHAR" does not exist
LINE 1: ...dio_clip_id" WHERE (CAST("collections"."title" AS "VARCHAR")...

Version: 2.0.13

full query

Rails version: 6.0.3.4
PG version: 1.2.3

(0.8ms)  SELECT
    COUNT( * ) AS "count_all"
    ,collections.id
    ,categories.name AS collections_id_categories_name
  FROM
    "collections" LEFT OUTER JOIN "categories"
      ON "categories" . "id" = "collections" . "category_id" LEFT OUTER JOIN "collection_tags"
      ON "collection_tags" . "collection_id" = "collections" . "id" LEFT OUTER JOIN "tags"
      ON "tags" . "id" = "collection_tags" . "tag_id" LEFT OUTER JOIN "taggings"
      ON "taggings" . "tag_id" = "tags" . "id" LEFT OUTER JOIN "audio_clips"
      ON "audio_clips" . "id" = "taggings" . "audio_clip_id"
  WHERE
    (
      CAST (
        "collections" . "title" AS "VARCHAR"
      ) ILIKE '%a%'
    )
    OR (
      CAST (
        "categories" . "name" AS "VARCHAR"
      ) ILIKE '%a%'
    )
  GROUP BY
    collections.id
    ,categories.name
  ORDER BY
    "collections" . "created_at" DESC

When using functionality with https://github.com/jbox-web/ajax-datatables-rails

snex commented

I am having the same issue. Also a different issue breaks group/aggregate queries. Will open a new issue for that.

I've hit the same error, it seems to be the 'AS' statement is followed by an extra ". In my case:

/lib/patches/db/pg.rb:69:in `exec_params': PG::SyntaxError: ERROR:  zero-length delimited identifier at or near """" (ActiveRecord::StatementInvalid)                               
LINE 1: ...AS "count_all", "analysis_jobs_items"."status" AS ""analysis...