Questions tagged [rawsql]

95 questions
2
votes
2 answers

Rewrite raw SQL as Django query

I am trying to write this raw SQL query, info_model = list(InfoModel.objects.raw('SELECT *, max(date), count(postid) AS freq, count(DISTINCT author) AS contributors FROM …
Shane G
  • 3,129
  • 10
  • 43
  • 85
2
votes
1 answer

Python/Django object.filter(pk__in=variable_list)

I'm making a raw query where my result of select id from table looks like this: [(517L,), (519L,), (526L,), (537L,), (668L,), (670L,), (671L,), (672L,), (673L,)] I need to use these ids with the __in filter to receive the correct objects here is…
liv a
  • 3,232
  • 6
  • 35
  • 76
2
votes
2 answers

Django: objects.raw() unable to fetch results despite SQL working in MySQL directly

I've written a function for Django which allows a user to enter a word or phrase, and fetch all the instances in a specified model where that instance has all those words appear in any order across a range of specified fields. I have chosen to use…
michaeljtbrooks
  • 162
  • 2
  • 11
2
votes
1 answer

play framework ebean RawSql paging

Should it be possible to use Paging with a custom SQL ebean query? For example, when I set up this query: String sql = "SELECT q.event_id AS event_id," + " MIN(q.total_price) AS price_min, " + "…
1
vote
1 answer

Django copying sqlite table columns

I have two sqlite.db files. I'd like to copy the contents of one column in a table of on db file to another. for example: I have the model Information in db file 1: class Information(models.Model): info_id = models.AutoField(primary_key =…
JohnnyCash
  • 1,231
  • 6
  • 17
  • 28
1
vote
1 answer

EXEC sp_executesql framed from "FromSQLRaw" not working as expected

I'm trying to get some details from Database using our EF core application with the help of "fromSQLRaw" function by framing the Query. This is the Final Query that I wanted to build to get the desired results and this query is working fine…
Mounika
  • 13
  • 2
1
vote
1 answer

Sequelize raw query update array of objects as replacements

I am using sequelize (postgres) and I need to properly escape a query like this: ` UPDATE "Pets" SET "name" = CASE LOWER("name") ${input.pets .map((pet) => `WHEN '${pet.name.toLowerCase()}' THEN '${pet.newName}'`) …
pakut2
  • 500
  • 5
  • 21
1
vote
0 answers

How to use LIKE %a% when passing a parameter in raw sql django

I have a parameter search_query and I want to get all the objects that consist search_query using only raw sql(I know that Django has built-in functions for that) Here is my code: def search(request): cursor = connection.cursor() …
james54
  • 53
  • 4
1
vote
1 answer

How to check a request.user with raw sql in Django

I want to get data about a Student which is currently logged in Here is my code: def profile(request): cursor = connection.cursor() a = request.user.id cursor.execute("SELECT * from Student WHERE ID = a ") data =…
james54
  • 53
  • 4
1
vote
0 answers

Getting error when I try to convert raw queryset to queryset

The query itself is correct and I am able to get the raw query set. 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 why I created SQL query,…
1
vote
3 answers

How can I specific columns using FromSqlRaw in EF.core

I just used FromSqlRaw. In Microsoft tutorial enter link description here, using FromSqlRaw has to select all columns (pls, I haven't seen some good examples as well). But what I want is to select some specific columns when joining several…
1
vote
1 answer

EF Core 5 and FromSqlRaw with inheritance

I want to use a FromSqlRaw query with view models and inheritance between them. I created two example view models: public class SummaryVM { public int Quantity { get; set; } public int Value { get; set; } } public class DistrictVM :…
sada
  • 584
  • 2
  • 8
  • 25
1
vote
0 answers

Djano Queryset returned from Manager with Stored Procedure

I have a model.Manager that runs a stored procedure and a model.Model to handle the returned data. However, when the data is returned, it's not returned as a queryset but instead a list of tuples, and I cannot reference them by field name. I would…
AlliDeacon
  • 1,365
  • 3
  • 21
  • 35
1
vote
1 answer

Filtering rows by datetime plus number of days in django queryset

I have a model with a field datetime as reference date and a field integer that holds the number of days to count from reference date, I need to filter out the rows whos reference_date + days is lesser than current date in django orm. I have tried…
Alejandro
  • 51
  • 6
1
vote
1 answer

Changing database content with raw SQL brings EntityFramework context out of sync

I have a table A that has a foreign key relation to another table B. First I delete an entry (a) in A using raw SQL. Later I delete an entry in table B, b, which was the entry that a was pointing to. When I do this, EntityFramework fails with the…
Thorkil Værge
  • 2,727
  • 5
  • 32
  • 48