Обсуждение: Using pgAdminIII to view the data written in PostGreSQL

Поиск
Список
Период
Сортировка

Using pgAdminIII to view the data written in PostGreSQL

От
Serge Christian Ibala
Дата:

Hello All,

I have written a small code in Python to write data in a database (PostGreSQL) using psycopg2 Library. 


The python code seems to work very well. My problem starts when I want to see the data I put in the database (PostGreSQL) using pgAdminIII


I can connect to the database very well but I cannot see the data. Does anybody have a small that present the following points?

a)     Write data in PostGreSQL database with Python

b)     then go see the data written in PostGreSQL data base with pgAdminIII

 

I have seen on google that few people had the same problem.

Thank you.

Kind Regards,

Christian. 

Re: Using pgAdminIII to view the data written in PostGreSQL

От
Adrian Klaver
Дата:
On 02/17/2016 04:13 PM, Serge Christian Ibala wrote:
> Hello All,
>
> I have written a small code in Python to write data in a database
> (PostGreSQL) using psycopg2 Library.
>
>
> The python code seems to work very well. My problem starts when I want
> to see the data I put in the database (PostGreSQL) using pgAdminIII
>
>
> I can connect to the database very well but I cannot see the data. Does
> anybody have a small that present the following points?
>
> a)Write data in PostGreSQL database with Python
>
> b)then go see the data written in PostGreSQL data base with pgAdminIII

You are using two separate sessions and if you do not issue a COMMIT in
a) you will not see the data in b)

>
> I have seen on google that few people had the same problem.
>
> Thank you.
>
> Kind Regards,
>
> Christian.
>


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: Using pgAdminIII to view the data written in PostGreSQL

От
Adrian Klaver
Дата:
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.klaver@aklaver.com