From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Parthan <parth(dot)technofreak(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Error in PostgreSQL query with psycopg |
Date: | 2006-07-31 16:38:26 |
Message-ID: | 44CE3202.9090308@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Parthan wrote:
> Hello,
>
> Am not sure whether i can post such a question over here, still the
> error is in my postgresql query syntax, hence i post it in this mailing
> list. sorry if am wrong.
>
> I am getting a 'type error' with the following query.
>
> [Code]
>
> Line68:
> query = cursor.execute("""INSERT INTO ConfMain (ConfName, ConfHost,
> ConfStart, ConfEnd, ConfDays, ConfStartTime, ConfEndTime, ConfSize)
> VALUES (\'%s\', \'%s\', \'%%\', \'%%\', %i, \'%%\', \'%%\', %i);""" %
> (conf_name, host_name, start_day, end_day, int(num_days), start_time,
> end_time, aud_size))
Does psycopg not handle quoting for you? Almost all database interfaces
nowadays support something like:
result = myquery.execute('INSERT INTO foo (anInt,aDate,aText) VALUES
(?,?,?)', query_parameters);
The interface deals with quoting the "?" based on the type definitions
in the database.
Trying to quote things yourself is tricky. You'll need to handle
single-quotes in a string yourself - easy to get it wrong.
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | Parthan SR | 2006-07-31 17:10:14 | Re: Error in PostgreSQL query with psycopg |
Previous Message | Richard Huxton | 2006-07-31 16:29:52 | Re: Antw: Re: Query questions |