inserting integer in Table
Thomas SMETS
tsmets at altern.org
Thu Jul 27 19:36:39 EDT 2000
Well Roland,
didn't work at my place ...
I reCREATED a similar table with a column defined as int4 & bearing the
name pk.
<snip>
tsmets=> create table TESTPYTHON
tsmets-> ( pk integer, filename varchar(99), file bytea );
</snip>
I couldn't insert a simple integer with you command :
i = 0
conn.query("insert into TESTPYTHON pk values ( %s );" % i)
Exception thrown is :
<snip>
Traceback (innermost last):
File "insertBlobs.py", line 15, in ?
conn.query("insert into TESTPYTHON (pk) values ( %s );" % i)
pg.error: ERROR: Relation 'testpython' does not have attribute 'pk'
</snip>
Shouldn't I use %i or something like that instead of %s ?
Tx,
Thomas,
===============
Roland Schlenker wrote:
>
> Thomas SMETS wrote:
>
> > In PostgreSQL table is :
> > <snip>
> > test=> \d test_blob_s;
> > Table = test_blob_s
> > +----------------------------------+----------------------------------+-------+
> > | Field | Type |
> > Length|
> > +----------------------------------+----------------------------------+-------+
> > | filenumber | int4
> > | 4 |
> > | filename | varchar()
> > | 100 |
> > | filecontent | oid
> > | 4 |
> > +----------------------------------+----------------------------------+-------+
> > test=>
> > </snip>
> >
> > Now I'm willing to insert in that table rows like this one :
> > <i>, <file_name_i>, <file_name_i_content>.
> >
> > Here's is the (not-so-running) code :
> >
> > <snip>
> > #
> > #
> > # ############################################
> > import os, glob
> > from pg import DB
> >
> > conn=DB('test')
> > conn.query("BEGIN WORK;")
> >
> > i = 0
> > for name in glob.glob("*.jpg"):
> > print "Name is ", name,
> > try:
> > conn.query("insert into test_blob_s filenumber values (" + i +
> > ")")
>
> conn.query("insert into test_blob_s values (%s);" % i)
>
> >
> > print " inserted"
> > except TypeError,e:
> > print '\nerror ', e, 'undefined'
> > # conn.query( "update test_blob_s set filename = '" + name + "')")
>
> # conn,query("update test_blob_s set filename = '%s';" % name)
>
> >
> > # conn.query( "update test_blob_s set filecontent = '" +
> > lo_import(name) + "')")
>
> # conn.query("update test_blob_s set filecontent = %s;" %
> lo_import(name))
>
> >
> >
> > i = i + 1
> >
> > conn.query(" COMMIT WORK;");
> >
> > </snip>
> >
> > of course I can't have it passing the insert of "i"
> > Could some one help ?
> >
> > Thomas,
> >
> > --
> >
> > Thomas SMETS Phone : +32 (0)2 742. 05. 94.
> > Av. de la Brabançonne 133 / 3 e-mail : tsmets @altern.org
> > 1030 Bruxelles
> >
> > ==== Quote of the day =========
> > You shouldn't wallow in self-pity. But it's OK to put your feet in it
> > and swish them around a little.
> > -- Guindon
> > ======= End of Quote =========
>
> Roland Schlenker
--
Thomas SMETS Phone : +32 (0)2 742. 05. 94.
Av. de la Brabançonne 133 / 3 e-mail : tsmets @altern.org
1030 Bruxelles
==== Quote of the day =========
Your true value depends entirely on what you are compared with.
======= End of Quote =========
More information about the Python-list
mailing list