PG Grouping Error - mysql

I have tried the suggested solutions on similar topics but they don't work.
MenuItem.where(cat: s.cat).group(:subcat).find_each do |w|
The code above works in the development environment which uses sqlite3 but throws out the following error in the deployment environment which uses postgresql:
PG::GroupingError: ERROR: column "menu_items.id" must appear in the GROUP BY clause or be used in an aggregate function
Any help on solving the issue will be greatly appreciated!

PG::GroupingError: ERROR: column "menu_items.id" must appear in the
GROUP BY clause or be used in an aggregate function
Try the below query
MenuItem.where(cat: s.cat).group(:id, :subcat).find_each do |w|

Related

SQLAlchemy - Unable to reflect SQL view

I'm getting the following error message when trying to reflect any of my SQL views:
sqlalchemy/dialects/mysql/reflection.py", line 306, in _describe_to_create
buffer.append(" ".join(line))
TypeError: sequence item 2: expected str instance, bytes found
I have tried using both the autoload_with and autoload=True options in my select query constructor to no avail.
I have the appropriate permissions on my view. My query is pretty simple:
company_country = Table('company_country', metadata, autoload_with=engine)
query = select(company_country.c.country)
return query
I've tried the inspect utility and it does not list my SQL view, nor does the reflecting all tables described below the views section on this page: https://docs.sqlalchemy.org/en/14/core/reflection.html#reflecting-views
I'm using version SQLAlchemy->1.4.32, Python 3.x and mySQL 8.0.28 on Mac if that's any help
I should add that I can query my SQL views using the text() constructor but it would be far more preferable to use select() if possible.
Any tips appreciated
I was using the mysql-connector client for interop with other code, but after switching to the mysqlclient, I was able to reflect the views.
https://docs.sqlalchemy.org/en/14/dialects/mysql.html#module-sqlalchemy.dialects.mysql.mysqldb

apache drill - AssertionError: Relational expression

running apache-drill-1.14.0
tested this query on mysql and got result in 0.02 sec
running the query in drill cli fails with AssertionError
Query:
product_id is BIGINT
SELECT test50.customername, test50.color, test50.age, test50.city,
test50.product_id, test50.price FROM myplugin.sampler.test50 JOIN
myplugin.sampler.test52 ON test50.product_id = test52.product_id WHERE
test50.product_id = 759216 GROUP BY test50.customername, test50.color,
test50.age, test50.city, test50.product_id, test50.price ORDER BY
test50.customername;
Error:
Error: SYSTEM ERROR: AssertionError: Relational expression
rel#873:DrillFilterRel.JDBC.myplugin.ANY([]).
[](input=rel#83:JdbcTableScan.JDBC.myplugin.ANY([]).[](table=[myplugin,
sampler, test50]),condition=OR(=($18, 759216), =($18, 494636))) has
calling-convention JDBC.myplugin but does not implement the required interface
'interface org.apache.calcite.adapter.jdbc.JdbcRel' of that convention
need help if I need some extra configuration ?
Thanks
Could you please check on current master? Looks like it was fixed in DRILL-6850.

Mysql to Postgresql Rails PG::GroupingError: ERROR:

I just deployed my app and had to switch from mysql to postgresql.
Now when executing my query I get following error:
ActiveRecord::StatementInvalid (PG::GroupingError: ERROR: column "search_terms.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "search_terms".* FROM "search_terms" WHERE (search_te...
^
: SELECT "search_terms".* FROM "search_terms" WHERE (search_terms.term like '%%') GROUP BY search_terms.game_id):
I have a table called search_terms with term:string and game_id:integer. A game can have multiple terms. So I want to group the terms that match by the game_id.
Does anyone know how to solve this?
In my model search_term.rb, I have defined this search function:
# Search Terms
def self.search(query)
where("search_terms.term like ?", "%#{query}%").group("search_terms.game_id")
end
Thank you for any help.
I think this is what you need to try.
def self.search(query)
where("search_terms.term like ?", "%#{query}%").group("search_terms.game_id", "search_terms.term")
end
explanation here: Rails 3.1 with PostgreSQL: GROUP BY must be used in an aggregate function

Like and group by in Laravel 4.2

I use group by with a count function in LARAVEL 4.2. When I tried to use LIKE in the same query, it gave me the error Invalid use of group function, as we can't use like with group by. How can I solve this?
You can't use Mysql aggregate function with group & like both together you have to use having instead of like.
Check here MySQL :: MySQL 5.0 Reference Manual :: 12.16.3 MySQL Handling of GROUP BY
and here: A similar SO question answer

Multiple functions in a $where clause

I am constructing a url for a CMS data query. I get the following to work just fine:
https://data.cms.gov/resource/din4-7td8.json?$$app_token=REDACTED&$where=(starts_with(nppes_provider_zip,'63703') OR starts_with(nppes_provider_zip,'63701')) AND (hcpcs_code='31623' OR hcpcs_code='31622')
When I try to substitute calling multiple hcpcs_code values, I get a query.compiler.malformed error. The following generates the error:
https://data.cms.gov/resource/din4-7td8.json?$$app_token=REDACTED&$where=(starts_with(nppes_provider_zip,'63703') OR starts_with(nppes_provider_zip,'63701') AND hcpcs_code in('31622','31623'))
Is it possible that I am using the in(...) function incorrectly?
I think I may have caught you on IRC after you asked this question, but I'll answer here too.
It looks like you're using an old version of that API endpoint which doesn't support the IN(...) function. If you migrate to the new version of that dataset API you'll be able to issue your query:
http://dev.socrata.com/foundry/#/data.cms.gov/5fnr-qp4c
https://data.cms.gov/resource/5fnr-qp4c.json?$where=(starts_with(nppes_provider_zip,'63703') OR starts_with(nppes_provider_zip,'63701') AND hcpcs_code in('31622','31623'))