Connect python application with postgreSQL database using psycopg2.
Perform DDL & DML operations
Create table , Insert/update/delete and select records
Understand connection & cursor class
This document contains 21 JavaScript interview questions related to topics such as:
1. The difference between undefined and not defined.
2. Examples testing output for functions, closures, and object properties.
3. Private methods, emptying arrays, checking array types, and function hoisting.
4. Operator behavior, typeof, delete, and instanceof.
5. Calculating the length of an associative array.
The document encourages checking answers and provides links to detailed explanations for each question.
Rob Pike discusses Plan 9, an operating system developed at Bell Labs as the successor to UNIX. Some key points of Plan 9 include its use of /proc instead of /dev for I/O, its distributed file system design with everything treated as a file, and its emphasis on concurrency through lightweight processes and message passing. Plan 9 aims to improve on UNIX with a more unified and simplified design.
The document provides information about Core Java concepts including:
1. James Gosling initiated the Java language project in 1991 and Sun released the first public implementation as Java 1.0 in 1995 with the promise of "Write Once, Run Anywhere".
2. Oracle acquired Sun Microsystems in 2010 and has worked to build fully integrated systems optimized for performance.
3. The document discusses the differences between C++ and Java and covers Java concepts like objects, classes, methods, variables, data types, identifiers, arrays and the Java Virtual Machine (JVM).
Perl is a general-purpose programming language created by Larry Wall in 1987. It supports both procedural and object-oriented programming. Perl is useful for tasks like web development, system administration, text processing and more due to its powerful built-in support for text processing and large collection of third-party modules. Basic Perl syntax includes variables starting with $, @, and % for scalars, arrays, and hashes respectively. Conditional and looping constructs like if/else, while, and for are also supported.
The document provides an agenda and introduction for a Java training over multiple days. Day 1 will cover an introduction to Java including its history, features, programming paradigm, sample program execution, JVM, data types, objects, classes, variables, and flow control statements. The training will cover key Java concepts like objects, classes, variables, different loops and conditional statements. Assignments are provided to practice the concepts covered.
JavaScript was created in 10 days in 1995 by Brendan Eich for Netscape Navigator to allow dynamic interactions on web pages. Originally called Mocha, it was renamed JavaScript to capitalize on the popularity of Java at the time despite having no relation. Microsoft later created its own version called JScript. In 1996-1997, JavaScript was standardized as ECMAScript, with ECMAScript 3 becoming the baseline for modern JavaScript and the latest version being ECMAScript 6 from 2015.
This document provides an introduction to JavaScript including:
- JavaScript is the most popular programming language for adding interactivity to web pages.
- It is embedded directly into HTML and is case-sensitive.
- JavaScript can change HTML content, attributes, styles, validate data, and display pop-ups.
- The <script> tag is used to insert JavaScript into HTML. Scripts can go in the head or body.
- External JavaScript files allow code reuse across pages and improve performance.
- JavaScript outputs can be written to alerts, the page, elements, and the console.
- Variables, data types, operators, functions, conditional statements, loops, arrays and events are also introduced.
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Dinesh Neupane
This presentation covers the basic idea of connecting postgresql database with python and psycopg2 module.
Covered Topics:
1. Psycopg2 Installation
2. Connecting to PostgreSQL Database
3. Connection Parameters
4. Create and Drop Table
5. Adaptation of Python Values to SQL Types
6. SQL Transactions
7. DML
Psycopg2 - Connect to PostgreSQL using Python ScriptSurvey Department
It's the presentation slides I prepared for my college workshop. This demonstrates how you can talk with PostgreSql db using python scripting.For queries, mail at [email protected]
This document discusses using Python to connect to and interact with a PostgreSQL database. It covers:
- Popular Python database drivers for PostgreSQL, including Psycopg which is the most full-featured.
- The basics of connecting to a database, executing queries, and fetching results using the DB-API standard. This includes passing parameters, handling different data types, and error handling.
- Additional Psycopg features like server-side cursors, transaction handling, and custom connection factories to access columns by name rather than number.
In summary, it provides an overview of using Python with PostgreSQL for both basic and advanced database operations from the Python side.
This document discusses Python database programming. It introduces databases and how they store data in tables connected through columns. It discusses SQL for creating, accessing, and manipulating database data. It then discusses how Python supports various databases and database operations. It covers the Python DB-API for providing a standard interface for database programming. It provides examples of connecting to a database, executing queries, and retrieving and inserting data.
This document discusses connecting Python programs to databases. It covers:
1. Importing database modules for MySQL and PostgreSQL.
2. Establishing a connection to the database using connect() and handling connection errors.
3. Creating a cursor object to execute SQL commands.
4. Executing SQL queries like SELECT and INSERT using the cursor's execute() method.
5. Fetching data from the database using cursor methods like fetchall(), fetchmany(), and fetchone().
This document discusses connecting to a PostgresSQL database using the Psycopg2 library in Python. It provides steps for installing Psycopg2, connecting to an existing database, executing commands like creating a table, querying the database, and retrieving data. Functions for connecting, creating cursors, committing transactions, and closing connections are also overviewed. An example Python code snippet demonstrates importing Psycopg2, connecting to a database, executing a query, fetching the results, and closing the connection.
This document discusses connecting Python to databases. It outlines 4 steps: 1) importing database modules, 2) establishing a connection, 3) creating a cursor object, and 4) executing SQL queries. It provides code examples for connecting to MySQL and PostgreSQL databases, creating a cursor, and fetching data using methods like fetchall(), fetchmany(), and fetchone(). The document is an introduction to connecting Python applications to various database servers.
This document discusses using SQLAlchemy to access relational databases from Python. It provides an overview of SQLAlchemy, describing its core SQL expression language and object-relational mapper (ORM). SQLAlchemy provides tools and components to assist with database access while maintaining a consistent interface over the Python DB-API. It allows generating SQL statements and mapping database rows to Python objects for a more object-oriented programming experience.
Relational Database Access with Python ‘sans’ ORM Mark Rees
This document discusses various approaches for accessing relational databases from Python, including ORM libraries like Django and SQLAlchemy, raw SQL queries using the Python DB-API standard, and template libraries like SpringPython. It provides code examples for common database operations like SELECT, INSERT, and comparing database schemas. A number of Python database adapters are also described, supporting databases like PostgreSQL, MySQL, SQLite and more.
This document discusses using Python to interact with SQLite databases. It provides examples of how to connect to an SQLite database, create tables, insert/update/delete records, and query the database. Key points covered include using the sqlite3 module to connect to a database, getting a cursor object to execute SQL statements, and various cursor methods like execute(), executemany(), fetchone(), fetchall(), commit(), and close(). Example code is given for common SQLite operations like creating a table, inserting records, updating records, deleting records, and selecting records.
This document discusses how to connect a Python script to a MySQL database using the mysql.connector library. It provides steps to establish a connection, create a cursor object, execute SQL queries, fetch data from the cursor, close the connection, and use parameterized queries for inserting, updating, and selecting data from the database.
The Python DB-API standard supports connecting to and interacting with many database servers like MySQL, PostgreSQL, and Oracle. To access a database, a Python module like MySQLdb must be installed. Code examples demonstrate how to connect to a MySQL database, create tables, insert/update/delete records, and handle errors according to the DB-API. Transactions ensure data integrity using atomicity, consistency, isolation, and durability properties.
PythonDatabaseAPI -Presentation for Databasedharawagh9999
Python DB API allows Python applications to interact with relational databases in a uniform way. It supports various databases including SQLite, MySQL, PostgreSQL, Oracle, and SQL Server. The document discusses connecting Python to MySQL, executing SQL queries, and fetching data. It provides code to connect to a MySQL database, create a table, insert sample data, run queries, and display results.
Connecting Python to MySQL allows storing and retrieving data from a MySQL database. The mysql.connector module provides a bridge between Python and MySQL. To connect, import mysql.connector, create a connection object specifying login details, then use cursor objects to execute queries and extract result sets. Queries can be parameterized by embedding placeholders in SQL strings. Data is inserted or updated using execute() and changes committed with commit().
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecdrazelitouali
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
More Related Content
Similar to Psycopg2 postgres python DDL Operaytions (select , Insert , update, create table) (20)
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Dinesh Neupane
This presentation covers the basic idea of connecting postgresql database with python and psycopg2 module.
Covered Topics:
1. Psycopg2 Installation
2. Connecting to PostgreSQL Database
3. Connection Parameters
4. Create and Drop Table
5. Adaptation of Python Values to SQL Types
6. SQL Transactions
7. DML
Psycopg2 - Connect to PostgreSQL using Python ScriptSurvey Department
It's the presentation slides I prepared for my college workshop. This demonstrates how you can talk with PostgreSql db using python scripting.For queries, mail at [email protected]
This document discusses using Python to connect to and interact with a PostgreSQL database. It covers:
- Popular Python database drivers for PostgreSQL, including Psycopg which is the most full-featured.
- The basics of connecting to a database, executing queries, and fetching results using the DB-API standard. This includes passing parameters, handling different data types, and error handling.
- Additional Psycopg features like server-side cursors, transaction handling, and custom connection factories to access columns by name rather than number.
In summary, it provides an overview of using Python with PostgreSQL for both basic and advanced database operations from the Python side.
This document discusses Python database programming. It introduces databases and how they store data in tables connected through columns. It discusses SQL for creating, accessing, and manipulating database data. It then discusses how Python supports various databases and database operations. It covers the Python DB-API for providing a standard interface for database programming. It provides examples of connecting to a database, executing queries, and retrieving and inserting data.
This document discusses connecting Python programs to databases. It covers:
1. Importing database modules for MySQL and PostgreSQL.
2. Establishing a connection to the database using connect() and handling connection errors.
3. Creating a cursor object to execute SQL commands.
4. Executing SQL queries like SELECT and INSERT using the cursor's execute() method.
5. Fetching data from the database using cursor methods like fetchall(), fetchmany(), and fetchone().
This document discusses connecting to a PostgresSQL database using the Psycopg2 library in Python. It provides steps for installing Psycopg2, connecting to an existing database, executing commands like creating a table, querying the database, and retrieving data. Functions for connecting, creating cursors, committing transactions, and closing connections are also overviewed. An example Python code snippet demonstrates importing Psycopg2, connecting to a database, executing a query, fetching the results, and closing the connection.
This document discusses connecting Python to databases. It outlines 4 steps: 1) importing database modules, 2) establishing a connection, 3) creating a cursor object, and 4) executing SQL queries. It provides code examples for connecting to MySQL and PostgreSQL databases, creating a cursor, and fetching data using methods like fetchall(), fetchmany(), and fetchone(). The document is an introduction to connecting Python applications to various database servers.
This document discusses using SQLAlchemy to access relational databases from Python. It provides an overview of SQLAlchemy, describing its core SQL expression language and object-relational mapper (ORM). SQLAlchemy provides tools and components to assist with database access while maintaining a consistent interface over the Python DB-API. It allows generating SQL statements and mapping database rows to Python objects for a more object-oriented programming experience.
Relational Database Access with Python ‘sans’ ORM Mark Rees
This document discusses various approaches for accessing relational databases from Python, including ORM libraries like Django and SQLAlchemy, raw SQL queries using the Python DB-API standard, and template libraries like SpringPython. It provides code examples for common database operations like SELECT, INSERT, and comparing database schemas. A number of Python database adapters are also described, supporting databases like PostgreSQL, MySQL, SQLite and more.
This document discusses using Python to interact with SQLite databases. It provides examples of how to connect to an SQLite database, create tables, insert/update/delete records, and query the database. Key points covered include using the sqlite3 module to connect to a database, getting a cursor object to execute SQL statements, and various cursor methods like execute(), executemany(), fetchone(), fetchall(), commit(), and close(). Example code is given for common SQLite operations like creating a table, inserting records, updating records, deleting records, and selecting records.
This document discusses how to connect a Python script to a MySQL database using the mysql.connector library. It provides steps to establish a connection, create a cursor object, execute SQL queries, fetch data from the cursor, close the connection, and use parameterized queries for inserting, updating, and selecting data from the database.
The Python DB-API standard supports connecting to and interacting with many database servers like MySQL, PostgreSQL, and Oracle. To access a database, a Python module like MySQLdb must be installed. Code examples demonstrate how to connect to a MySQL database, create tables, insert/update/delete records, and handle errors according to the DB-API. Transactions ensure data integrity using atomicity, consistency, isolation, and durability properties.
PythonDatabaseAPI -Presentation for Databasedharawagh9999
Python DB API allows Python applications to interact with relational databases in a uniform way. It supports various databases including SQLite, MySQL, PostgreSQL, Oracle, and SQL Server. The document discusses connecting Python to MySQL, executing SQL queries, and fetching data. It provides code to connect to a MySQL database, create a table, insert sample data, run queries, and display results.
Connecting Python to MySQL allows storing and retrieving data from a MySQL database. The mysql.connector module provides a bridge between Python and MySQL. To connect, import mysql.connector, create a connection object specifying login details, then use cursor objects to execute queries and extract result sets. Queries can be parameterized by embedding placeholders in SQL strings. Data is inserted or updated using execute() and changes committed with commit().
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecdrazelitouali
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptxBelicia R.S
Role play : First Aid- CPR, Recovery position and Hand hygiene.
Scene 1: Three friends are shopping in a mall
Scene 2: One of the friend becomes victim to electric shock.
Scene 3: Arrival of a first aider
Steps:
Safety First
Evaluate the victim‘s condition
Call for help
Perform CPR- Secure an open airway, Chest compression, Recuse breaths.
Put the victim in Recovery position if unconscious and breathing normally.
Sustainable Innovation with Immersive LearningLeonel Morgado
Prof. Leonel and Prof. Dennis approached educational uses, practices, and strategies of using immersion as a lens to interpret, design, and planning educational activities in a sustainable way. Rather than one-off gimmicks, the intent is to enable instructors (and institutions) to be able to include them in their regular activities, including the ability to evaluate and redesign them.
Immersion as a phenomenon enables interpreting pedagogical activities in a learning-agnostic way: you take a stance on the learning theory to follow, and leverage immersion to envision and guide your practice.
Available Sun June 8th, for Weekend June 14th/15th.
Timeless for Summer 25.
Our libraries do host classes for a year plus in most shops. Timelines do vary.
See also our Workshops 8, 9, and 2 Grad/Guest Updates.
Workshop 9 was uploaded early also for Weekend June 14th/15th.
Reiki Yoga Level 1 - Practitioner Studies. For our June Schedules
I luv the concept of effortless learning. My Background includes traditional & Distant Education. My Fav classes were online. A few on Campus recent years.
So, for LDMMIA I believe in Self-Help, Self-Care, Self-Serve lol. “How can my followers/readers privately attend courses?” So this season, I do want to expand our new Merch Shop. This includes digital production like no other - Wow. More Updates this Mo lol.
Merch Host: teespring.com
How to Configure Vendor Management in Lunch App of Odoo 18Celine George
The Vendor management in the Lunch app of Odoo 18 is the central hub for managing all aspects of the restaurants or caterers that provide food for your employees.
This presentation has been made keeping in mind the students of undergraduate and postgraduate level. To keep the facts in a natural form and to display the material in more detail, the help of various books, websites and online medium has been taken. Whatever medium the material or facts have been taken from, an attempt has been made by the presenter to give their reference at the end.
In the seventh century, the rule of Sindh state was in the hands of Rai dynasty. We know the names of five kings of this dynasty- Rai Divji, Rai Singhras, Rai Sahasi, Rai Sihras II and Rai Sahasi II. During the time of Rai Sihras II, Nimruz of Persia attacked Sindh and killed him. After the return of the Persians, Rai Sahasi II became the king. After killing him, one of his Brahmin ministers named Chach took over the throne. He married the widow of Rai Sahasi and became the ruler of entire Sindh by suppressing the rebellions of the governors.
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...Rajdeep Bavaliya
Get ready to embark on a cosmic quest as we unpack the archetypal power behind Christopher Nolan’s ‘Interstellar.’ Discover how hero’s journey tropes, mythic symbols like wormholes and tesseracts, and themes of love, sacrifice, and environmental urgency shape this epic odyssey. Whether you’re a film theory buff or a casual viewer, you’ll learn why Cooper’s journey resonates with timeless myths—and what it means for our own future. Smash that like button, and follow for more deep dives into cinema’s greatest stories!
M.A. Sem - 2 | Presentation
Presentation Season - 2
Paper - 109: Literary Theory & Criticism and Indian Aesthetics
Submitted Date: April 5, 2025
Paper Name: Literary Theory & Criticism and Indian Aesthetics
Topic: Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes in Nolan’s Cosmic Odyssey
[Please copy the link and paste it into any web browser to access the content.]
Video Link: https://youtu.be/vHLaLZPHumk
For a more in-depth discussion of this presentation, please visit the full blog post at the following link: https://rajdeepbavaliya2.blogspot.com/2025/04/archetypal-journeys-in-interstellar-exploring-universal-themes-in-nolan-s-cosmic-odyssey.html
Please visit this blog to explore additional presentations from this season:
Hashtags:
#ChristopherNolan #Interstellar #NolanFilms #HeroJourney #CosmicOdyssey #FilmTheory #ArchetypalCriticism #SciFiCinema #TimeDilation #EnvironmentalCinema #MythicStorytelling
Keyword Tags:
Interstellar analysis, Christopher Nolan archetypes, hero’s journey explained, wormhole symbolism, tesseract meaning, myth in sci-fi, cinematic archetypes, environmental themes film, love across time, Nolan film breakdown
How to Manage & Create a New Department in Odoo 18 EmployeeCeline George
In Odoo 18's Employee module, organizing your workforce into departments enhances management and reporting efficiency. Departments are a crucial organizational unit within the Employee module.
ABCs of Bookkeeping for Nonprofits TechSoup.pdfTechSoup
Accounting can be hard enough if you haven’t studied it in school. Nonprofit accounting is actually very different and more challenging still.
Need help? Join Nonprofit CPA and QuickBooks expert Gregg Bossen in this first-time webinar and learn the ABCs of keeping books for a nonprofit organization.
Key takeaways
* What accounting is and how it works
* How to read a financial statement
* What financial statements should be given to the board each month
* What three things nonprofits are required to track
What features to use in QuickBooks to track programs and grants
Battle of Bookworms is a literature quiz organized by Pragya, UEM Kolkata, as part of their cultural fest Ecstasia. Curated by quizmasters Drisana Bhattacharyya, Argha Saha, and Aniket Adhikari, the quiz was a dynamic mix of classical literature, modern writing, mythology, regional texts, and experimental literary forms. It began with a 20-question prelim round where ‘star questions’ played a key tie-breaking role. The top 8 teams moved into advanced rounds, where they faced audio-visual challenges, pounce/bounce formats, immunity tokens, and theme-based risk-reward questions. From Orwell and Hemingway to Tagore and Sarala Das, the quiz traversed a global and Indian literary landscape. Unique rounds explored slipstream fiction, constrained writing, adaptations, and true crime literature. It included signature IDs, character identifications, and open-pounce selections. Questions were crafted to test contextual understanding, narrative knowledge, and authorial intent, making the quiz both intellectually rewarding and culturally rich. Battle of Bookworms proved literature quizzes can be insightful, creative, and deeply enjoyable for all.
Completed Sunday 6/8. For Weekend 6/14 & 15th. (Fathers Day Weekend US.) These workshops are also timeless for future students TY. No admissions needed.
A 9th FREE WORKSHOP
Reiki - Yoga
“Intuition-II, The Chakras”
Your Attendance is valued.
We hit over 5k views for Spring Workshops and Updates-TY.
Thank you for attending our workshops.
If you are new, do welcome.
Grad Students: I am planning a Reiki-Yoga Master Course (As a package). I’m Fusing both together.
This will include the foundation of each practice. Our Free Workshops can be used with any Reiki Yoga training package. Traditional Reiki does host rules and ethics. Its silent and within the JP Culture/Area/Training/Word of Mouth. It allows remote healing but there’s limits As practitioners and masters, we are not allowed to share certain secrets/tools. Some content is designed only for “Masters”. Some yoga are similar like the Kriya Yoga-Church (Vowed Lessons). We will review both Reiki and Yoga (Master tools) in the Course upcoming.
S9/This Week’s Focus:
* A continuation of Intuition-2 Development. We will review the Chakra System - Our temple. A misguided, misused situation lol. This will also serve Attunement later.
Thx for tuning in. Your time investment is valued. I do select topics related to our timeline and community. For those seeking upgrades or Reiki Levels. Stay tuned for our June packages. It’s for self employed/Practitioners/Coaches…
Review & Topics:
* Reiki Is Japanese Energy Healing used Globally.
* Yoga is over 5k years old from India. It hosts many styles, teacher versions, and it’s Mainstream now vs decades ago.
* Anything of the Holistic, Wellness Department can be fused together. My origins are Alternative, Complementary Medicine. In short, I call this ND. I am also a metaphysician. I learnt during the 90s New Age Era. I forget we just hit another wavy. It’s GenZ word of Mouth, their New Age Era. WHOA, History Repeats lol. We are fusing together.
* So, most of you have experienced your Spiritual Awakening. However; The journey wont be perfect. There will be some roller coaster events. The perks are: We are in a faster Spiritual Zone than the 90s. There’s more support and information available.
(See Presentation for all sections, THX AGAIN.)
4. Steps
1) Create Connection string
2) Open connection
3) Open cursor
4) Execute cursor
5) Close Cursor
6) Close Connection
5. Connection
Connection class
Handles connection to database instances
Encapsulates a database session
Connection String Example
psycopg2.connect(database="sample",user="postgres",password="sample",
host="127.0.0.1", port="5432")
connection.cursor( )
creates a cursor which will be used throughout of your database programming
with Python
6. Connection Method ( )
connection.commit ( )
Commits the current transaction
Changes will not reflect to other connections if not commited
Default, psycopg opens a transaction before executing the first command
connection.rollback( )
This method rolls back any changes to the database since the last call to
commit( )
connection.close( )
This Method closes the database connection.
If you close your database connection without calling commit() first, your
changes will
be lost!
7. CURSOR
Cursor is Class
Allows Python code to execute PostgreSQL
command in a database session
Created by
connection.cursor( ) Method
cursor.execute( ), cursor.fetch( ),cursor.close( )
8. Execute( )
cursor.execute (query [, optional parameters])
Execute a database operation (query or command)
returns None.
Cursor.execute(“select * from test”)
The returned values can be retrieved using fetch*( )
methods
cursor.executemany(query, vars_list)
Execute a database operation (query or command)
against all parameter tuples or mappings found in
the sequence vars_list
9. Call Procedures
cursor.callproc(procname[, parameters])
- Call database stored procedure
- The sequence of parameters must contain one entry for
each argument that the procedure expects
- Overloaded procedure supported
- The procedure may provide a result set as output.
- This is then made available through the standard fetch*()
methods
10. Fetch()
cursor.fetchone( )
- Fetch the next row of a query result set, returning a single tuple
cursor.fetchall( )
- This routine fetches all (remaining) rows of a query result, returning a
list. An empty list is returned when no rows are available.
cursor.fetchmany([size=cursor.arraysize])
- Fetch the next set of rows of a query result, returning a list of
tuples.An empty list is returned when no more rows are available.
11. Cursor.*
Cursor.rowcount
This read-only attribute which returns the total number of database rows that
have been modified, inserted, or deleted by the last last execute*().
Cursor.query
Returns last executed query
12. DDL/DML OPERATIONS
-- Create Table
-- Drop Table
-- Insert Record
-- Update Record
-- Select Record
-- Delete Record
14. Select
import psycopg2
conn = psycopg2.connect(database = "postgres",
user = "postgres", password = "postgres", host =
"127.0.0.1", port = "5432")
cursor = conn.cursor()
cursor.execute("select * from test2")
data = cursor.fetchone()
cursor.execute("select * from test2")
data = cursor.fetchmany(2)
15. Create Table
import psycopg2
conn = psycopg2.connect(database =
"postgres", user = "postgres", password =
"postgres", host = "127.0.0.1", port =
"5432")
print ("Opened database successfully")
cur = conn.cursor()
cur.execute('''CREATE TABLE COMPS
(ID INT PRIMARY KEY NOT NULL,
16. Insert
#CREATE TABLE
- cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer,
data varchar(99));")
- conn.commit
#INSERT/UPDATE RECORD
cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100,
"sqlnosql.com"))
conn.commit
#UPDATE
cursor.execute("UPDATE test2 set num = 999 where ID = 4")
conn.commit
cursor.rowcount