craft-assetusage icon indicating copy to clipboard operation
craft-assetusage copied to clipboard

Not compatible with PostgreSQL?

Open Marcuzz opened this issue 1 year ago • 3 comments

Hi,

When using this plugin with PostgreSQL we seem to be encountering a lot of errors with several SQL queries. For example:

https://github.com/born05/craft-assetusage/blob/dc6b7575ef710498be684150be959254d5147ecd/src/console/controllers/DefaultController.php#L71-L72

The columns in PostgreSQL are transformed to lowercase unless they are wrapped in double quotes, and PostgreSQL is case-sensitive. For these queries to work the column has to be wrapped in double quotes, i.e: relations."targetId"

There is another issue on the following lines as well:

https://github.com/born05/craft-assetusage/blob/dc6b7575ef710498be684150be959254d5147ecd/src/console/controllers/DefaultController.php#L77-L78

There is a type incompatible comparison here. "LIKE" is only possible on text/strings, but "content" is a jsonb column.

There are more similar PostgreSQL errors, here: https://github.com/born05/craft-assetusage/blob/dc6b7575ef710498be684150be959254d5147ecd/src/services/Asset.php#L92-L93

I'm not sure what the best way to fix this is, while keeping compatibility with MySQL as well, so I figured I'd just create an issue as opposed to a PR.

Marcuzz avatar Nov 18 '24 14:11 Marcuzz

Same issue, installed fine but is erroring on the usage of "LIKE"

Image

cherrykoda avatar Apr 22 '25 14:04 cherrykoda

+1

SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: jsonb ~~ unknown
LINE 3: WHERE ("content" LIKE $1) OR ("content" LIKE $2)
                         ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
The SQL being executed was: SELECT "elementId" AS "id", "siteId"
FROM "elements_sites"
WHERE ("content" LIKE '%asset:27923:%') OR ("content" LIKE '%"imageId": "27923",%')

niektenhoopen avatar Aug 04 '25 14:08 niektenhoopen

@Marcuzz @cherrykoda Can you please test https://github.com/born05/craft-assetusage/pull/51 ?

@roelvanhintum Can you verify that this still works on MySQL?

niektenhoopen avatar Aug 04 '25 14:08 niektenhoopen