Error in PostgreSQL query with psycopg

From: Parthan <parth(dot)technofreak(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Error in PostgreSQL query with psycopg
Date: 2006-07-31 14:50:57
Message-ID: 44CE18D1.4070806@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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))

Line80:
main(num_days)

[/Code]

Error:

Traceback (most recent call last): File
"/usr/lib/cgi-bin/ConfSachem/page2.py", line 80, in ? main(num_days)
File "/usr/lib/cgi-bin/ConfSachem/page2.py", line 73, in main
DbaseInsert(conf_name, host_name, start_day, end_day, num_days,
start_time, end_time) File "/usr/lib/cgi-bin/ConfSachem/page2.py", line
68, in DbaseInsert query = cursor.execute("""INSERT INTO ConfMain
(ConfName, ConfHost, ConfStart, ConfEnd, ConfDays, ConfStartTime,
ConfEndTime, ConfSize) VALUES (\'%s\', \'%s\', \'%s\', \'%s\', %i,
\'%s\', \'%s\', %i)""" % (conf_name, host_name, start_day, end_day,
int(num_days), start_time, end_time, aud_size)) TypeError: int argument
required

The input is from the form and is transfered to variables. These
variables are passed as arguments to the DbaseInsert() function.

ConfName and ConfHost are varchars
ConfStart and ConfEnd are date
ConfStartTime and ConfEndTime are time
ConfDays and ConfSize are integer

I am going wrong either in passing the values through arguments or in
the string formatting used? How will i pass the date and time data which
are in the form of 'dd-mm-yyyy' and 'hh:mm:ms' as required by the date
and time data types of PostgreSQL ?

Am i wrong in useing back slash escaped single quotes to quote strings
in the query? Am using it with values for strings, date and time, while
i dont use it with %i for integers.
--
With Regards

Parthan ('technofreak')
------------------------------
Research Assistant @ NRC-FOSS and Python\PHP Developer
A Proud Tuxian and an Ubuntero

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2006-07-31 14:53:42 Re: Practical maximums (was Re: PostgreSQL theoretical
Previous Message Christian Rengstl 2006-07-31 14:22:18 Antw: Re: Query questions