Questions tagged [rawsql]

95 questions
111
votes
8 answers

How to execute a raw update sql with dynamic binding in rails

I want to execute one update raw sql like below: update table set f1=? where f2=? and f3=? This SQL will be executed by ActiveRecord::Base.connection.execute, but I don't know how to pass the dynamic parameter values into the method. Could someone…
ywenbo
  • 3,051
  • 6
  • 31
  • 46
12
votes
3 answers

Get the last inserted id in django

I am migrating some data from other databases , so i am using raw sql queries for inserting data into database . But i don't know how to get last inserted id from raw sql queries in django. I have tried this…
user1746291
  • 323
  • 2
  • 5
  • 15
12
votes
6 answers

Error: Cursor' object has no attribute '_last_executed

I have this cursor cursor.execute("SELECT price FROM Items WHERE itemID = ( SELECT item_id FROM Purchases WHERE purchaseID = %d AND customer_id = %d)", [self.purchaseID, self.customer]) I get…
skinnyas123
  • 382
  • 1
  • 4
  • 13
7
votes
2 answers

EF 4.1 - DBContext SqlQuery and Include

I want to execute a raw sql using DBContext SqlQuery and then include related entites. I've tried the following but it doesn't load the related entities: string sql = "Select * from client where id in (select id from activeclient)"; var list =…
sysboard
  • 287
  • 7
  • 19
7
votes
1 answer

Execute raw SQL query in ASP.NET MVC, database first mode

The model of my project is database first, and uses remote access to database on another server. I need to use raw SQL query because my query is very complex and I feel more comfortable in SQl not LINQ. This is how I do: string query =…
user2093360
  • 249
  • 3
  • 4
  • 8
5
votes
1 answer

% confuses python raw sql query

Following this SO question, I'm trying to "truncate" all tables related to a certain django application using the following raw sql commands in python: cursor.execute("set foreign_key_checks = 0") cursor.execute("select concat('truncate table…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
4
votes
2 answers

Laravel 9: how to insert data using raw sql while doing a migration?

I've a "static" table I need to import while doing initial migrations on my project. I've a .sql file. It's a lot of data, > 35k records My idea was to create table in a standard migration and then, with "something" execute the insert sql I already…
realtebo
  • 23,922
  • 37
  • 112
  • 189
4
votes
1 answer

Speed comparison between Eloquent ORM, Query Builder, and Raw SQL Queries

Does anyone has the data of speed comparison between Eloquent ORM, Query Builder, and Raw SQL Queries? What is the better choose?
mrakodol
  • 1,143
  • 3
  • 12
  • 41
2
votes
2 answers

How to set an entity field that does not exist on the table but does exists in the raw SQL as an alias?

Lets say that we have a query like this one: SELECT *, (CUSTOM_EXPRESSION) as virtualfield FROM users The user's entity itself has the "virtualfield" but the mapping annotations no, since the table doesn't have this field. Assuming that it is…
Keyne Viana
  • 6,194
  • 2
  • 24
  • 55
2
votes
1 answer

typeorm inner join and where problem - BaseEntity model

I use typeorm (^0.2.41) and define two model which extends from my custom BaseModel: BaseModel: import { BaseEntity } from 'typeorm'; export class BaseModel extends BaseEntity { } Category: @Entity('Category', { schema: 'public' }) export class…
2
votes
1 answer

if tag not working when using raw sql in django template

When I am using raw sql for a variable say myvar = some rawsql and when I am checking in if condition in query for myvar it is always true. {% if myvar %} do this; {% else %} do this; {% endif %} For instance my raw sql returns 0 records then I…
vkrams
  • 7,267
  • 17
  • 79
  • 129
2
votes
0 answers

How to add a SQLServer Full Text Search in Django?

In Django, one can use full text search natively when using Postgres. However, when using it with SQL Server (and django-pyodbc-azure) there is no simple way to do it (as far I know). To do a full text search in SQL Server you use the…
Dewes
  • 23
  • 6
2
votes
2 answers

Passing Optional List argument from Django to filter with in Raw SQL

When using primitive types such as Integer, I can without any problems do a query like this: with connection.cursor() as cursor: cursor.execute(sql='''SELECT count(*) FROM account WHERE %(pk)s ISNULL OR id %(pk)s''', params={'pk':…
radoh
  • 4,554
  • 5
  • 30
  • 45
2
votes
2 answers

`?` placeholder for SQL `IN` condition with persistent's `rawSql`

I would be happy to use ? placeholder to populate ids for SQL IN clause. Unfortunately the following does not work let idList :: [ RequestId ] idList = [] let sql :: String sql = "SELECT ?? FROM request WHERE request.id IN ?" rs <- runDB $…
Geradlus_RU
  • 1,466
  • 2
  • 20
  • 37
2
votes
1 answer

Get related column on .annotate() data Django

I created this simple set of data to illustrate my point. It is a simple model with no further relations to any other model. I need to group the data above by topicid, find the max date for each group and then get the author for that date. info =…
Shane G
  • 3,129
  • 10
  • 43
  • 85
1
2 3 4 5 6 7