I'm running a simple query:
Listing.where('advertiserName LIKE ?', '%lowes%')
and I get the following error
Listing.where('advertiserName LIKE ?', '%lowes%')
D, [2021-09-13T00:26:42.656409 #4] DEBUG -- : Listing Load (1.6ms) SELECT "listings".* FROM "listings" WHERE (advertiserName LIKE '%lowes%') LIMIT $1 [["LIMIT", 11]]
Traceback (most recent call last):
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column "advertisername" does not exist)
LINE 1: SELECT "listings".* FROM "listings" WHERE (advertiserName LI...
^
HINT: Perhaps you meant to reference the column "listings.advertiserName".
4 attempts to solve
1
I double checked the column name exists:
Listing.column_names
=> ["id", "language", "jobId", "jobTitle", "jobClassification", "jobSubClassification", "advertiserName", "advertiserId",
2
I made sure I was using single quotes like PostgreSQL requires.
3
I ran a similar query on another table in the same app, and it seems to work just fine:
Metric.where('average_salary_by_language LIKE ?', '%Hadoop%')
# returns results
4
I did as suggested in the error message, and tried replacing advertiserName
with listings.advertiserName
:
Listing.where('listings.advertiserName LIKE ?', '%lowes%')
D, [2021-09-13T00:31:36.017492 #4] DEBUG -- : Listing Load (1.7ms) SELECT "listings".* FROM "listings" WHERE (listings.advertiserName LIKE '%lowes%') LIMIT $1 [["LIMIT", 11]]
Traceback (most recent call last):
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column listings.advertisername does not exist)
LINE 1: SELECT "listings".* FROM "listings" WHERE (listings.advertis...
^
HINT: Perhaps you meant to reference the column "listings.advertiserName".
Other ideas
I can see the error message says:
PG::UndefinedColumn: ERROR: column listings.advertisername does not exist
I know that advertisername
doesn't exist - it's clearly advertiserName
(with a capital 'N'), and that's what I'm using. Could rails/AR/postgres have a bug?