SlideShare a Scribd company logo
selvamani@selvamani-laptop:~$ sudo su - postgres
[sudo] password for selvamani:
postgres@selvamani-laptop:~$ psql -U pgsqldemouser pgsqldemodb
psql (8.4.3)
Type "help" for help.

pgsqldemodb=> create table pgsqldemotable(sno varchar(3), name varchar(30));
CREATE TABLE
pgsqldemodb=> insert into pgsqldemotable values('1','Arulalan');
INSERT 0 1
pgsqldemodb=> insert into pgsqldemotable values('2','BalaKrishnan');
INSERT 0 1
pgsqldemodb=> insert into pgsqldemotable values('3','Dhasthagheer');
INSERT 0 1
pgsqldemodb=> insert into pgsqldemotable values('4','Selvamani');
INSERT 0 1
pgsqldemodb=> select * from pgsqldemotable;
 sno | name
-----+--------------
 1 | Arulalan
 2 | BalaKrishnan
 3 | Dhasthagheer
 4 | Selvamani
(4 rows)

pgsqldemodb=> alter role pgsqldemouser with password 'demo';
ALTER ROLE
pgsqldemodb=> q
postgres@selvamani-laptop:~$ logout
selvamani@selvamani-laptop:~$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> connection=psycopg2.connect("host=localhost dbname=pgsqldemodb user=pgsqldemouser
password=demo")
cur=connection.cursor()
>>> cur.execute("""select * from pgsqldemotable""")
>>> a=cur.fetchall()
>>> print a
[('1', 'Arulalan'), ('2', 'BalaKrishnan'),('3','Dhasthagheer'), ('4', 'Selvamani')]
>>> type(a)
<type 'list'>
>>> type(a[0])
<type 'tuple'>
>>> type(a[0][0])
<type 'str'>
>>> type(a[0][1])
<type 'str'>
>>> a[0][1]
'Arulalan'
>>> a[1][1]
'BalaKrishnan'
>>> cur.execute("""insert into pgsqldemotable values('5','Rajkumar')""")
>>> connection.commit()
>>> sno=raw_input("""Enter the value:""")
Enter the value:6
>>> name=raw_input("""Enter the value:""")
Enter the value:Shrinivasan
>>> cur.execute("""insert into pgsqldemotable values('%s','%s')""" %(sno,name))
>>> connection.commit()
>>> exit()
selvamani@selvamani-laptop:~$ sudo su - postgres
postgres@selvamani-laptop:~$ psql -U pgsqldemouser -W pgsqldemodb
Password for user pgsqldemouser:
psql (8.4.3)
Type "help" for help.

pgsqldemodb=> select * from pgsqldemotable;
 sno | name
-----+--------------
 1 | Arulalan
 2 | BalaKrishnan
 3 | Dhasthagheer
 4 | Selvamani
 5 | Rajkumar
 6 | Shrinivasan
(6 rows)

pgsqldemodb=> q
postgres@selvamani-laptop:~$ logout
selvamani@selvamani-laptop:~$

More Related Content

PPT
Shell and perl scripting classes in mumbai
PDF
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
DOCX
Save game function
PDF
Chrome拡張開発者のためのFirefox拡張開発
PDF
Provisionamento orquestrado nas nuvens com Juju
PDF
PubNative Tracker
KEY
Clojure入門
PDF
穏やかにファイルを削除する
Shell and perl scripting classes in mumbai
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Save game function
Chrome拡張開発者のためのFirefox拡張開発
Provisionamento orquestrado nas nuvens com Juju
PubNative Tracker
Clojure入門
穏やかにファイルを削除する

What's hot (20)

PPTX
20171014 tips for manipulating filesystem in julia
PDF
ランダム文字ぽいものをつくる
KEY
Advanced Shell Scripting
PDF
Drush - use full power - DrupalCamp Donetsk 2014
ODP
NUMOSS 4th Week - Commandline Tutorial
ODP
Linux Command Line
PDF
Leaks & Zombies
PDF
Solr integration in Magento Enterprise
KEY
テストデータどうしてますか?
PDF
WordPress Cuztom Helper
DOC
How to send files to remote server via ssh in php
PDF
Couchdb
PDF
You Don't Need Lodash
KEY
Paris js extensions
PDF
Puppet Camp Amsterdam 2015: Manifests of Future Past
KEY
MongoDB
PDF
Report: Avalanche 'very likely' to host outdoor game at Coors Field
PDF
Linux system admin
PDF
PostgreSQL (2) by Aswin
TXT
Pontos para criar_instancia_data guard_11g
20171014 tips for manipulating filesystem in julia
ランダム文字ぽいものをつくる
Advanced Shell Scripting
Drush - use full power - DrupalCamp Donetsk 2014
NUMOSS 4th Week - Commandline Tutorial
Linux Command Line
Leaks & Zombies
Solr integration in Magento Enterprise
テストデータどうしてますか?
WordPress Cuztom Helper
How to send files to remote server via ssh in php
Couchdb
You Don't Need Lodash
Paris js extensions
Puppet Camp Amsterdam 2015: Manifests of Future Past
MongoDB
Report: Avalanche 'very likely' to host outdoor game at Coors Field
Linux system admin
PostgreSQL (2) by Aswin
Pontos para criar_instancia_data guard_11g
Ad

Viewers also liked (7)

PDF
Michael Campbell Visual Resume PCP
DOCX
Bcom 275 final exam guide 19) Which verbal support breaks down complex proces...
PDF
DOCX
Dream the work retreat agenda
PPT
EDRM LegalTech NY 2009 Luncheon Presentation
PPTX
Gsj11 bcn interesting websites
Michael Campbell Visual Resume PCP
Bcom 275 final exam guide 19) Which verbal support breaks down complex proces...
Dream the work retreat agenda
EDRM LegalTech NY 2009 Luncheon Presentation
Gsj11 bcn interesting websites
Ad

Similar to Klug pgsql tut (20)

PDF
PostgreSQL: How to Store Passwords Safely
PPTX
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
PDF
Programming with Python and PostgreSQL
ODP
OpenGurukul : Database : PostgreSQL
PDF
Neutralizing SQL Injection in PostgreSQL
PPTX
Psycopg2 - Connect to PostgreSQL using Python Script
PDF
Mastering PostgreSQL Administration
 
PDF
Mastering PostgreSQL Administration
PPTX
PPTX
PGEncryption_Tutorial
PDF
Learning postgresql
PDF
Best Practices in Security with PostgreSQL
 
PDF
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
PPTX
Best Practices in Security with PostgreSQL
 
PDF
Introduction to PostgreSQL
PDF
Postgresql quick guide
PPTX
Database connectivity in python
DOCX
Postgre sql run book
PPTX
Get Your Insecure PostgreSQL Passwords to SCRAM
PDF
Securing PostgreSQL from External Attack
PostgreSQL: How to Store Passwords Safely
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Programming with Python and PostgreSQL
OpenGurukul : Database : PostgreSQL
Neutralizing SQL Injection in PostgreSQL
Psycopg2 - Connect to PostgreSQL using Python Script
Mastering PostgreSQL Administration
 
Mastering PostgreSQL Administration
PGEncryption_Tutorial
Learning postgresql
Best Practices in Security with PostgreSQL
 
Whats wrong with postgres | PGConf EU 2019 | Craig Kerstiens
Best Practices in Security with PostgreSQL
 
Introduction to PostgreSQL
Postgresql quick guide
Database connectivity in python
Postgre sql run book
Get Your Insecure PostgreSQL Passwords to SCRAM
Securing PostgreSQL from External Attack

More from selvamanisampath (6)

PDF
Unix commands
PDF
Panipuri an-introduction-to-perfection-in-food-design
PDF
Death by-powerpoint4344
PDF
Glade & PYGTK
PDF
History Of Couch Db
PDF
Intro Couchdb
Unix commands
Panipuri an-introduction-to-perfection-in-food-design
Death by-powerpoint4344
Glade & PYGTK
History Of Couch Db
Intro Couchdb

Klug pgsql tut

  • 1. selvamani@selvamani-laptop:~$ sudo su - postgres [sudo] password for selvamani: postgres@selvamani-laptop:~$ psql -U pgsqldemouser pgsqldemodb psql (8.4.3) Type "help" for help. pgsqldemodb=> create table pgsqldemotable(sno varchar(3), name varchar(30)); CREATE TABLE pgsqldemodb=> insert into pgsqldemotable values('1','Arulalan'); INSERT 0 1 pgsqldemodb=> insert into pgsqldemotable values('2','BalaKrishnan'); INSERT 0 1 pgsqldemodb=> insert into pgsqldemotable values('3','Dhasthagheer'); INSERT 0 1 pgsqldemodb=> insert into pgsqldemotable values('4','Selvamani'); INSERT 0 1 pgsqldemodb=> select * from pgsqldemotable; sno | name -----+-------------- 1 | Arulalan 2 | BalaKrishnan 3 | Dhasthagheer 4 | Selvamani (4 rows) pgsqldemodb=> alter role pgsqldemouser with password 'demo'; ALTER ROLE pgsqldemodb=> q postgres@selvamani-laptop:~$ logout selvamani@selvamani-laptop:~$ python Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import psycopg2 >>> connection=psycopg2.connect("host=localhost dbname=pgsqldemodb user=pgsqldemouser password=demo") cur=connection.cursor() >>> cur.execute("""select * from pgsqldemotable""") >>> a=cur.fetchall() >>> print a [('1', 'Arulalan'), ('2', 'BalaKrishnan'),('3','Dhasthagheer'), ('4', 'Selvamani')] >>> type(a) <type 'list'> >>> type(a[0]) <type 'tuple'> >>> type(a[0][0]) <type 'str'> >>> type(a[0][1]) <type 'str'> >>> a[0][1] 'Arulalan' >>> a[1][1]
  • 2. 'BalaKrishnan' >>> cur.execute("""insert into pgsqldemotable values('5','Rajkumar')""") >>> connection.commit() >>> sno=raw_input("""Enter the value:""") Enter the value:6 >>> name=raw_input("""Enter the value:""") Enter the value:Shrinivasan >>> cur.execute("""insert into pgsqldemotable values('%s','%s')""" %(sno,name)) >>> connection.commit() >>> exit() selvamani@selvamani-laptop:~$ sudo su - postgres postgres@selvamani-laptop:~$ psql -U pgsqldemouser -W pgsqldemodb Password for user pgsqldemouser: psql (8.4.3) Type "help" for help. pgsqldemodb=> select * from pgsqldemotable; sno | name -----+-------------- 1 | Arulalan 2 | BalaKrishnan 3 | Dhasthagheer 4 | Selvamani 5 | Rajkumar 6 | Shrinivasan (6 rows) pgsqldemodb=> q postgres@selvamani-laptop:~$ logout selvamani@selvamani-laptop:~$