From: | Jonathan Rogers <jrogers(at)socialserve(dot)com> |
---|---|
To: | psycopg(at)postgresql(dot)org |
Subject: | Re: Encountered an error |
Date: | 2016-03-15 08:05:10 |
Message-ID: | 56E7C236.3080404@socialserve.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On 03/10/2016 12:37 AM, Shaan Repswal wrote:
> I am trying to insert a new record into my "prototypedb" database. This
> here below is the section of my code that I am using to access and work
> on my database.
>
> What I am trying to do here is enter one record (three values) in three
> columns name, code and type. Then create a new column and then add one
> value to the new column for the aforementioned already entered record.
>
> cur = conn.cursor()
>
> #Enter the three value basic record
> cur.execute("""INSERT INTO inventory (name, code, type)
> VALUES (%s, %s, %s);""",
> [self.entry_product_name.get_text(), self.new_product_code.get_text(),
> self.new_product_type.get_text()])
>
> #Take out list of Text Entry boxes
> #self.quantity_list is a list of two value tuples each of which
> holds a reference to a text box in my GUI
> for x in self.quantity_list:
> if x[0].get_text() !="" and x[1].get_text() != "":
> #First make the appropriate column
> cur.execute("""ALTER TABLE inventory
> ADD %s integer DEFAULT NULL;""",
> [x[0].get_text()])
> #Then give that column the appropriate value for the
> current record
> cur.execute("""UPDATE inventory
> SET %s = %s
> WHERE name = %s;""", [x[0].get_text(),
> x[1].get_text(), self.entry_product_name.get_text()])
> else:
> continue;
>
> conn.commit()
> cur.close()
> conn.close()
>
>
> But Alas! There is an Error!
>
> Traceback (most recent call last):
> File "C:\Python34\prototype_husk.py", line 134, in submit_data
> ADD %s integer DEFAULT NULL;""", [x[0].get_text()])
> psycopg2.ProgrammingError: syntax error at or near "'26.2 LTRS'"
> LINE 2: ADD '26.2 LTRS' integer DEFAULT ...
> ^
>
I'm having a very hard time imagining why it would ever make sense to
have a column called "26.2 LTRS", though Postgres will allow it. That
string represents a quantity in liters, correct? In that case, you
almost certainly want a column called something like "volume_in_liters"
into which you can insert the value "26.2".
--
Jonathan Rogers
Socialserve.com by Emphasys Software
jrogers(at)emphasys-software(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Karsten Hilbert | 2016-03-15 17:04:34 | Re: Encountered an error |
Previous Message | Jonathan Rogers | 2016-03-15 07:55:02 | Re: Encountered an error |