Re: Using pgAdminIII to view the data written in PostGreSQL

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Serge Christian Ibala <christian(dot)ibala(at)gmail(dot)com>
Cc: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Re: Using pgAdminIII to view the data written in PostGreSQL
Date: 2016-02-18 15:47:31
Message-ID: 56C5E793.5020606@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 02/18/2016 06:05 AM, Serge Christian Ibala wrote:
Ccing list.
> Hello Adrian,
>
> Thank you very much for writing back. I am using a commit in a) Please
> see below my python code to create the database.
>
> cur = conn.cursor()
> cur.execute('''CREATE TABLE COMPANY
> (IDINT PRIMARY KEY NOT NULL,
> NAMETEXT NOT NULL,
> AGEINT NOT NULL,
> ADDRESSCHAR(50),
> SALARYREAL);''')
>
> print(" Table created Successfully")
>
> conn.commit()
> conn.close()
>
>
> My python code to place the data in the data base
>
>
> cur = conn.cursor()
>
> cur.execute("INSERT INTO COMPANY (ID, NAME, AGE, ADDRESS, SALARY) \
> VALUES (1, 'Paul', 32, 'California', 20000.00)");
>
> cur.execute("INSERT INTO COMPANY (ID, NAME, AGE, ADDRESS, SALARY) \
> VALUES (2, 'ALLEN', 25, 'Texas', 15000.00)");
>
> cur.execute("INSERT INTO COMPANY (ID, NAME, AGE, ADDRESS, SALARY) \
> VALUES (3, 'Teddy', 23, 'Norway', 20000.00)");
>
> cur.execute("INSERT INTO COMPANY (ID, NAME, AGE, ADDRESS, SALARY) \
> VALUES (4, 'Mark', 25, 'Rich-Mond', 65000.00)");
>
> conn.commit()
>
>
> should I write to commit cur.commit() instead of conn.commit() ? I am not sure

conn.commit() is correct:

http://initd.org/psycopg/docs/connection.html

>
> to understand what you say.

I used your code above and it worked, in that it created and populated
the tables and I could see the table and its contents in pgAdmin3.

So further questions:

1) Are you connecting to the same database in pgAdmin3 as in your Python
script?

2) In your previous post you say you cannot see the data, does that mean
you cannot see the table at all, or you can see the table but not the
data you inserted?

3) Remember Postgres folds upper cased names to lower case unless the
name is enclosed in double quotes. So in your example code above the
table gets created as company not COMPANY.

4) Have you used psql to look at the database to see if the table and
its data is there?

>
> I can also go , Update, delete, display the data from the database.
>
>
> Again thank you for your email.
>
> Christian
>
> Ps: Do you please have a simple python example that you know work?
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse psycopg by date

  From Date Subject
Next Message Serge Christian Ibala 2016-02-19 20:00:59 How to use "WHERE NOT EXISTS in INSERT STATEMENT"
Previous Message Adrian Klaver 2016-02-18 13:42:54 Re: Using pgAdminIII to view the data written in PostGreSQL