[PyGreSQL] inserttable and get_tables syntax question

taso tasoadractas at gmail.com
Tue Apr 18 17:36:46 EDT 2006


Cool, that worked thanks a lot!!

Here is what I was doing:

Python 2.4.2 (#1, Apr 17 2006, 10:52:22)
[GCC 3.4.3 20050227 (Red Hat 3.4.3-22.1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import pg
 >>>
 >>> db = pg.connect('test', 'localhost', 5432, None, None, 'dbadmin', None)
 >>> db.get_tables()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: get_tables
 >>>
 >>> db.query("select count(*) from final")
count
-----
28
(1 row)


 >>>


So I was a little confused about the command syntax and params. I got 
the above connection sample off the pygresql.org site, and since the 
query worked I was lost when the get_ functionality was not available.

Anyhow thanks for the help!

Taso





Christoph Zwerschke wrote:

>> I have a few questions regarding the PyGreSql module. I'm new to 
>> python  so pardon my lack of  knowledge. When trying to use any of 
>> the "get_"  functions (get_databases, get_tables) I receive an 
>> "AttributeError". Same thing with "inserttable". Wondering if someone 
>> could post a quick example including creation of a database 
>> connection and executing the above three functions. I suspect my 
>> syntax is off because I can successfully connect to and query from my 
>> database, but I can not find any syntactical examples anywhere to 
>> confirm my suspicion.
>
>
> Hi Taso,
>
> here is a Python session you can try out (you can create an empty 
> database for testing with "createdb mydb"):
>
> ------
>
> python
>
> >>> from pg import DB
> >>> db = DB('mydb')
> >>> db.get_databases()
>
> ['template0', 'template1', 'mydb']
>
> >>> db.query('create table mytable (n integer, t text)')
> >>> db.get_tables()
>
> ['public.mytable']
>
> >>> db.inserttable('mytable', [(1, 'hello'), (2, 'world')])
>
> >>> db.query('select * from mytable').getresult()
>
> [(1, 'hello'), (2, 'world')]
>
> >>> db.get('mytable', 2, 'n')
>
> {'n': 2, 't': 'world', 'oid(public.mytable)': ...}
>
> ------
>
> Hope that helps.
>
> -- Christoph
>



More information about the PyGreSQL mailing list