Questions tagged [rawsql]

95 questions
0
votes
1 answer

Laravel raw sql query

select CONCAT(app_users.first_name) as display_name,COUNT(NewLeads.id) from `app_users` LEFT JOIN (SELECT app_leads.id, app_leads.owner_user_id from app_leads JOIN app_lead_version ON app_leads.id=app_lead_version.lead_id WHERE `app_leads`.`flag` =…
Gautam
  • 1
  • 2
0
votes
1 answer

How to handle several search fields on one page using raw sql?

I have for now two serach field(planning to add more) and I want to use only raw sql whem filtering the objects(I know that Django provides ORM which makes life so much easier, but in my work right now I need to use SQL) I know how to do it with ORM…
user5790
  • 61
  • 7
0
votes
1 answer

How to avoid N+1 problem with native SQL query in springboot with Hibernate?

I'm querying my DB with POSTGIS built-ins to retrieve the closest Machines given a Location. I have to use a native SQL because Hibernate does not support POSTGIS and CTEs: @Repository public interface MachineRepository extends…
sweetacaro
  • 105
  • 6
0
votes
2 answers

How to search by the date?

I am trying to search records between two date range from database. Here is my code views: def profile(request): if request.method == 'POST': fromdate = request.POST.get('from') todate = request.POST.get('to') cursordate…
james54
  • 53
  • 4
0
votes
1 answer

How to insert data into table using Sqlalchemy ORM?

I am trying to copy the data from one table to another table. Normally using the SELECT command, we can read the whole table, and using the INSERT command we can insert the data into another table. But I don't want to use raw SQL command, I want to…
0
votes
2 answers

Django Error "django.db.utils.ProgrammingError: subquery has too many columns "

The raw query itself is correct and I am able to get retrieve the rawqueryset from the db. I need to convert this into queryset for further processing and I am facing below error. Creating corresponding django query was hard for me and that is why I…
0
votes
0 answers

How to convert raw queryset to queryset?

The raw query itself is correct and I am able to get retrieve the raw query set from the db. I need to convert this into query set for further processing and I am facing below error. Creating corresponding django query was hard for me and that is…
0
votes
1 answer

Can't get Laravel OrderBy date to work in Eloquent statement

I need to pull the records in date order, but having spent hours researching this and trying many approaches and variations in my code, I'm getting nowhere. I need to sort on the left_employer_date field, which is a VARCHAR format. So I'm trying to…
Hondaman900
  • 109
  • 2
  • 14
0
votes
1 answer

Django raw sql statement with params and likes search

I have a problem when performing a raw sql in Django. res = [] start = '2017-12-08T01:56:56.701Z' end = '2020-12-08T01:56:56.701Z' with connection.cursor() as cursor: raw_sql = ''' select case when content like '%products%' then…
Charles
  • 199
  • 3
  • 8
0
votes
1 answer

sql query : perform a where in if condition

i've a situation like the following : i've a long query that join a table all the columns in joined tabled contain a column 'name'. in this table there are two names 'A' and 'B' (but can be C,D......Z, i don't know how many names we can have) and…
dack funk
  • 43
  • 6
0
votes
2 answers

UPDATE in raw sql does not hit all records although they meet the criteria

I am trying to update several records when I hit the save button in the admin with a raw sql which is located in models.py (def save(self, *args, **kwargs) The raw sql is like this as a prototype cursor=connection.cursor() cursor.execute("UPDATE…
Helmut
  • 233
  • 5
  • 14
0
votes
0 answers

Raw SQL to Django ORM queryset conversion

Here I have a queryset where I am using raw SQL to get data. But this approach is not fulfilling my requirements. I want to convert this query into pure Django ORM query queryset = Model.objects.raw("select id,category,count(category) as…
0
votes
1 answer

a raw sql query is not working in django framework. I am getting "TypeError at / not all arguments converted during string formatting"

select *from table_name where name = %s",params={"name1","name2"} full_code: from django.shortcuts import render from . models import destination def index(request,params = None): dests1 = destination.objects.raw("select *from…
0
votes
3 answers

How to make a raw SQL query that selects the city with the highest population associated with an area code (there are duplicate area codes)

I have a table that has the following columns: areaCode zipcode city state population There are multiple rows with the same area codes that are associated with different cities/zip codes. I need to select the city with the highest population that…
sbuck89
  • 123
  • 3
  • 6
0
votes
0 answers

Django (2.0.1) Row SQL Query - Putting Results into Templates Html *Raw query must include the primary key*

I am trying to fetch data from my database and displaying the results in a template. However, the results are not displayed. Result on the website is: "Raw query must include the primary key". This is my code: This is my code in the view: class…
user2208882
  • 77
  • 1
  • 4