Re: Using pgAdminIII to view the data written in PostGreSQL

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Using pgAdminIII to view the data written in PostGreSQL
Дата
Msg-id 56C5E793.5020606@aklaver.com
обсуждение исходный текст
Ответ на Using pgAdminIII to view the data written in PostGreSQL  (Serge Christian Ibala <christian.ibala@gmail.com>)
Список 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.klaver@aklaver.com


В списке psycopg по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Using pgAdminIII to view the data written in PostGreSQL
Следующее
От: Alan Evans
Дата:
Сообщение: PQntuples for older version (2.2.1) of psycopg2 with ctypes