We are using django and sql, so we have written query in sql , here my request is how can I convert sql query to django query.Please let me know
You can use ModelName.objects.raw() to run SQL queries which will return model Instances.
Refer: https://docs.djangoproject.com/en/2.2/topics/db/sql/
or to execute directly from Database import connections from django.db.
Refer:https://docs.djangoproject.com/en/2.2/topics/db/sql/#executing-custom-sql-directly
Note: Django ORM is secure than normal SQL. If using raw SQL queries read docs on how to make raw SQL queries secure.
Related
I'm working on Sql server to Snowflake migration project,So i pointed ssrs reports to Snowflake data source and converting sql queries as per snowflake,but i'm not able to get how can we write queries for parameterized reports.Example select * from Student where Std_id=#id,want to convert to snowflake query.
You can use SQL variables:
https://docs.snowflake.com/en/sql-reference/session-variables.html
or Snowflake Scripting Variables:
https://docs.snowflake.com/en/developer-guide/snowflake-scripting/variables.html
I think the SQL variables would be helpful in your case, but Snowflake Scripting variables would be more similar to your SQL Server # variables.
in real projects or in industry usually use sequelize or sql query ? I'm still confused, is it better to use orm like sequelize or write sql queries?
I'd prefer to use raw SQL ( Mainly select + insert ) instead of O/R mapper, because it would be difficult to perform queries.
(The RDBMS is postgres9.4)
So the question is
Can I use raw SQL for logic part in Airflow?
You can create tasks that run raw SQL in a Postgres database directly using the PostgresOperator. You will need to set up your Postgres database as a Connection object in order for Airflow to know how to connect to the database.
I'd like to write stored procedures in pgSQL that dynamically generate web-ready data. I need a pure SQL to HTML or SQL to XML gateway. Oracle has OWA. In Oracle you can setup a RAC frontend to a SAN and connect a large set of OWA hosts to your RAC so you
layer your web requests and spread your queries.
What is the PostgreSQL or MySQL equivalent? I'm not looking at getting the data out of the DB, then processing it via Python or Ruby. Is something like
this even possible in PostgreSQL?
From experience, stored SQL procedures are better at moving/calculating large datasets than piping the SQL query/cursor/proc result set to a middleware Python/Ruby/Perl/PHP
that then process the data and send it to the web browser.
PostgreSQL has a host of functions that allow you to convert from tables/schemas/queries to XML ( http://www.postgresql.org/docs/8.4/static/functions-xml.html ) as well as a built-in XML datatype ( http://www.postgresql.org/docs/8.4/static/datatype-xml.html ).
Unfortunately, I can't give much more information than that as I'm not an XML guy but hopefully these references will make sense to you. ;)
What is a dynamic SQL query, and when would I want to use one? I'm using SQL Server 2005.
Here's a few articles:
Introduction to Dynamic SQL
Dynamic SQL Beginner's Guide
From Introduction to Dynamic SQL:
Dynamic SQL is a term used to mean SQL code that is generated programatically (in part or fully) by your program before it is executed. As a result it is a very flexible and powerful tool. You can use dynamic SQL to accomplish tasks such as adding where clauses to a search based on what fields are filled out on a form or to create tables with varying names.
Dynamic SQL is SQL generated by the calling program. This can be through an ORM tool, or ad-hoc by concatenating strings. Non-dynamic SQL would be something like a stored procedure, where the SQL to be executed is predefined. Not all DBA's will let you run dynamic SQL against their database due to security concerns.
A dynamic SQL query is one that is built as the program is running as opposed to a query that is already (hard-) coded at compile time.
The program in question might be running either on the client or application server (debatable if you'd still call it 'dynamic') or within the database server.