Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-11 Thread Jon Ribbens via Python-list
On 2024-09-11, Lawrence D'Oliveiro wrote: > On Tue, 10 Sep 2024 22:48:36 - (UTC), Jon Ribbens wrote: >> But what if you tell it the wrong thing ... > > To get back to the original point of this thread, all that rigmarole to > try to ensure to call “rollback” in case of an exception is complet

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-10 Thread Jon Ribbens via Python-list
On 2024-09-10, Lawrence D'Oliveiro wrote: > On Tue, 10 Sep 2024 08:38:30 - (UTC), Jon Ribbens wrote: > >> On 2024-09-09, Lawrence D'Oliveiro wrote: >>> >>> On Mon, 9 Sep 2024 21:12:51 - (UTC), Jon Ribbens wrote: On 2024-09-09, Lawrence D'Oliveiro wrote: > > On Mon, 9 Se

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-10 Thread Jon Ribbens via Python-list
On 2024-09-10, Karsten Hilbert wrote: > Am Tue, Sep 10, 2024 at 08:38:30AM - schrieb Jon Ribbens via Python-list: >> Ok. So we've moved away from "In any DBMS worth its salt, rollback is >> something that happens automatically" > > Nope. The original post asked something entirely different. N

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-10 Thread Karsten Hilbert via Python-list
Am Tue, Sep 10, 2024 at 08:38:30AM - schrieb Jon Ribbens via Python-list: > Ok. So we've moved away from "In any DBMS worth its salt, rollback is > something that happens automatically" Nope. The original post asked something entirely different. > and now you're saying it isn't automatic aft

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-10 Thread Jon Ribbens via Python-list
On 2024-09-09, Lawrence D'Oliveiro wrote: > On Mon, 9 Sep 2024 21:12:51 - (UTC), Jon Ribbens wrote: >> On 2024-09-09, Lawrence D'Oliveiro wrote: >>> On Mon, 9 Sep 2024 10:00:11 - (UTC), Jon Ribbens wrote: On 2024-09-09, Lawrence D'Oliveiro wrote: > The database only needs to com

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-09 Thread Jon Ribbens via Python-list
On 2024-09-09, Lawrence D'Oliveiro wrote: > On Mon, 9 Sep 2024 10:00:11 - (UTC), Jon Ribbens wrote: >> On 2024-09-09, Lawrence D'Oliveiro wrote: >>> The database only needs to commit when it is explicitly told. Anything >>> less -- no commit. >> >> So the Python code is half-way through a tr

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-09 Thread Jon Ribbens via Python-list
On 2024-09-09, Karsten Hilbert wrote: > Am Mon, Sep 09, 2024 at 10:00:11AM - schrieb Jon Ribbens via Python-list: >> So the Python code is half-way through a transaction when it throws >> a (non-database-related) exception and that thread of execution is >> aborted. The database connection ret

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-09 Thread Karsten Hilbert via Python-list
Am Mon, Sep 09, 2024 at 10:00:11AM - schrieb Jon Ribbens via Python-list: > So the Python code is half-way through a transaction when it throws > a (non-database-related) exception and that thread of execution is > aborted. The database connection returns to the pool, How does it return to th

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-09 Thread Karsten Hilbert via Python-list
Am Mon, Sep 09, 2024 at 10:00:11AM - schrieb Jon Ribbens via Python-list: > > The database only needs to commit when it is explicitly told. Anything > > less -- no commit. > > So the Python code is half-way through a transaction when it throws > a (non-database-related) exception and that thre

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-09 Thread Jon Ribbens via Python-list
On 2024-09-08, Lawrence D'Oliveiro wrote: > On Sun, 8 Sep 2024 11:03:21 - (UTC), Jon Ribbens wrote: >> What if there's an exception in your exception handler? I'd put the >> rollback in the 'finally' handler, so it's always called. If you've >> already called 'commit' then the rollback does no

Re: psycopg2 positioning of .commit() (Posting On Python-List Prohibited)

2024-09-09 Thread Jon Ribbens via Python-list
On 2024-09-09, Lawrence D'Oliveiro wrote: > On Mon, 9 Sep 2024 09:13:40 - (UTC), Jon Ribbens wrote: >> On 2024-09-08, Lawrence D'Oliveiro wrote: >>> On Sun, 8 Sep 2024 11:03:21 - (UTC), Jon Ribbens wrote: What if there's an exception in your exception handler? I'd put the rollba

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-09 Thread Jon Ribbens via Python-list
On 2024-09-08, Greg Ewing wrote: > On 8/09/24 9:20 am, Karsten Hilbert wrote: >> try: >> do something >> except: >> log something >> finally: >> .commit() >> >> cadence is fairly Pythonic and elegant in that it ensures the >> the .commit() wil

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-09 Thread Karsten Hilbert via Python-list
Am Mon, Sep 09, 2024 at 01:48:32PM +1200 schrieb Greg Ewing via Python-list: > That code doesn't inspire much confidence in me. It's far too > convoluted with too much micro-management of exceptions. It is catching two exceptions, re-raising both of them, except for re-raising one of them as anot

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-09 Thread Karsten Hilbert via Python-list
Am Mon, Sep 09, 2024 at 01:48:32PM +1200 schrieb Greg Ewing via Python-list: > That code doesn't inspire much confidence in me. It's far too > convoluted with too much micro-management of exceptions. > > I would much prefer to have just *one* place where exceptions are > caught and logged. I am o

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-08 Thread Greg Ewing via Python-list
On 9/09/24 2:13 am, Karsten Hilbert wrote: For what it's worth here's the current state of code: That code doesn't inspire much confidence in me. It's far too convoluted with too much micro-management of exceptions. I would much prefer to have just *one* place where exceptions are caught and l

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-08 Thread Greg Ewing via Python-list
On 8/09/24 11:03 pm, Jon Ribbens wrote: On 2024-09-08, Greg Ewing wrote: try: do something .commit() except: log something .rollback() What if there's an exception in your exception handler? I'd put the rollback in the 'finally' handler, so it's always called.

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-08 Thread Karsten Hilbert via Python-list
Am Sun, Sep 08, 2024 at 02:58:03PM +0100 schrieb Rob Cliffe via Python-list: > >Ugly: > > > > try: > > do something > > except: > > log something > > finally: > > try: > > .commit() > > except: > >

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-08 Thread Rob Cliffe via Python-list
On 07/09/2024 22:20, Karsten Hilbert via Python-list wrote: Am Sat, Sep 07, 2024 at 02:09:28PM -0700 schrieb Adrian Klaver: Right, and this was suggested elsewhere ;) And, yeah, the actual code is much more involved :-D I see that. The question is does the full code you show fail? The co

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-08 Thread Karsten Hilbert via Python-list
Am Sun, Sep 08, 2024 at 12:48:50PM +1200 schrieb Greg Ewing via Python-list: > On 8/09/24 9:20 am, Karsten Hilbert wrote: > > try: > > do something > > except: > > log something > > finally: > > .commit() > > > >cadence is fairly Pythonic and elegant

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-08 Thread Karsten Hilbert via Python-list
Am Sun, Sep 08, 2024 at 12:48:50PM +1200 schrieb Greg Ewing via Python-list: > On 8/09/24 9:20 am, Karsten Hilbert wrote: > > try: > > do something > > except: > > log something > > finally: > > .commit() > > > >cadence is fairly Pythonic and elegant

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-07 Thread Greg Ewing via Python-list
On 8/09/24 9:20 am, Karsten Hilbert wrote: try: do something except: log something finally: .commit() cadence is fairly Pythonic and elegant in that it ensures the the .commit() will always be reached regardless of exception

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-07 Thread Karsten Hilbert via Python-list
Am Sat, Sep 07, 2024 at 02:09:28PM -0700 schrieb Adrian Klaver: > >Right, and this was suggested elsewhere ;) > > > >And, yeah, the actual code is much more involved :-D > > > > I see that. > > The question is does the full code you show fail? > > The code sample you show in your original post is

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-07 Thread Karsten Hilbert via Python-list
Am Sat, Sep 07, 2024 at 01:03:34PM -0700 schrieb Adrian Klaver: > In the case you show you are doing commit() before the close() so any errors > in the > transactions will show up then. My first thought would be to wrap the > commit() in a > try/except and deal with error there. Right, and this

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-07 Thread Karsten Hilbert via Python-list
Am Sat, Sep 07, 2024 at 09:46:03AM -0700 schrieb Adrian Klaver: > >unto now I had been thinking this is a wise idiom (in code > >that needs not care whether it fails to do what it tries to > >do^1): > > > > conn = psycopg2.connection(...) > > In the above do you have: > > https://www.psycopg.o

Re: psycopg2: proper positioning of .commit() within try: except: blocks

2024-09-07 Thread Rob Cliffe via Python-list
On 07/09/2024 16:48, Karsten Hilbert via Python-list wrote: Dear all, unto now I had been thinking this is a wise idiom (in code that needs not care whether it fails to do what it tries to do^1): conn = psycopg2.connection(...) curs = conn.cursor() try: c

Re: PSYCOPG2

2021-02-13 Thread Mladen Gogala via Python-list
, 'DB_TYPE_ROWID', 'DB_T ... >>> conn=cx_Oracle.Connection("scott/tiger@ora19c") >>> Please use PSYCOPG2 instead of cx_Oracle. After you do it from python3 interpreter do it from Idle: On Sat, 13 Feb 2021 22:08:11 +

RE: PSYCOPG2

2021-02-13 Thread Tony Ogilvie
Subject: Re: PSYCOPG2 On Fri, 12 Feb 2021 18:29:48 +, Tony Ogilvie wrote: > I am trying to write a program to open a PostgesSQL 13 database using > psycopg2. All seems to work if I write direct to Python but if I write > the script into IDLE it does not work with the IDLE Shell 3.9.1 &g

Re: PSYCOPG2

2021-02-13 Thread dn via Python-list
On 13/02/2021 18.34, Mladen Gogala via Python-list wrote: > On Fri, 12 Feb 2021 18:29:48 +, Tony Ogilvie wrote: > >> I am trying to write a program to open a PostgesSQL 13 database using >> psycopg2. All seems to work if I write direct to Python but if I write >> the script into IDLE it does n

Re: PSYCOPG2

2021-02-13 Thread Sibylle Koczian
Am 13.02.2021 um 06:34 schrieb Mladen Gogala via Python-list: On Fri, 12 Feb 2021 18:29:48 +, Tony Ogilvie wrote: I am trying to write a program to open a PostgesSQL 13 database using psycopg2. All seems to work if I write direct to Python but if I write the script into IDLE it does not wor

Re: PSYCOPG2

2021-02-12 Thread Mladen Gogala via Python-list
On Fri, 12 Feb 2021 18:29:48 +, Tony Ogilvie wrote: > I am trying to write a program to open a PostgesSQL 13 database using > psycopg2. All seems to work if I write direct to Python but if I write > the script into IDLE it does not work with the IDLE Shell 3.9.1 > reporting an error of no attr

Re: psycopg2.ProgrammingError: syntax error at or near "\"

2017-10-27 Thread Karsten Hilbert
On Fri, Oct 27, 2017 at 08:35:20AM -0700, maheshyadav1...@gmail.com wrote: > I am using 'psycopg2' library to access my PostgreSQL database from a python. > I want to pass a variable input in psql query something like this :- > > psql>>\set my_user table1 > psql>>select * from :my_user limit 10

Re: Psycopg2 pool clarification

2017-06-10 Thread israel
On 2017-06-08 19:55, Ian Kelly wrote: On Thu, Jun 8, 2017 at 10:47 AM, Israel Brewster wrote: On Jun 7, 2017, at 10:31 PM, dieter wrote: israel writes: On 2017-06-06 22:53, dieter wrote: ... As such, using psycopg2's pool is essentially worthless for me (plenty of use for it, i'm sure, just

Re: Psycopg2 pool clarification

2017-06-08 Thread Ian Kelly
On Thu, Jun 8, 2017 at 10:47 AM, Israel Brewster wrote: >> On Jun 7, 2017, at 10:31 PM, dieter wrote: >> >> israel writes: >>> On 2017-06-06 22:53, dieter wrote: >>> ... >>> As such, using psycopg2's pool is essentially >>> worthless for me (plenty of use for it, i'm sure, just not for me/my >>>

Re: Psycopg2 pool clarification

2017-06-08 Thread Israel Brewster
--- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 --- > On Jun 7, 2017, at 10:31 PM, dieter wrote: > > israel writes: >> On 2017-06-06 22:53

Re: Psycopg2 pool clarification

2017-06-07 Thread dieter
israel writes: > On 2017-06-06 22:53, dieter wrote: > ... > As such, using psycopg2's pool is essentially > worthless for me (plenty of use for it, i'm sure, just not for me/my > use case). Could you not simply adjust the value for the "min" parameter? If you want at least "n" open connections, t

Re: Psycopg2 pool clarification

2017-06-07 Thread israel
On 2017-06-06 22:53, dieter wrote: israel writes: Since I've gotten no replies to this, I was wondering if someone could at least confirm which behavior (my expected or my observed) is *supposed* to be the correct? Should a psycopg2 pool keep connections open when returned to the pool (if close

Re: Psycopg2 pool clarification

2017-06-06 Thread dieter
israel writes: > Since I've gotten no replies to this, I was wondering if someone could > at least confirm which behavior (my expected or my observed) is > *supposed* to be the correct? Should a psycopg2 pool keep connections > open when returned to the pool (if closed is False), or should it > cl

Re: Psycopg2 pool clarification

2017-06-06 Thread israel
Since I've gotten no replies to this, I was wondering if someone could at least confirm which behavior (my expected or my observed) is *supposed* to be the correct? Should a psycopg2 pool keep connections open when returned to the pool (if closed is False), or should it close them as long as th

Re: Psycopg2 to create a record using a FK

2016-03-12 Thread Aaron Christensen
On Sat, Mar 12, 2016 at 9:57 PM, Aaron Christensen < aaron.christen...@gmail.com> wrote: > > > On Sat, Mar 12, 2016 at 5:03 AM, dieter wrote: > >> Aaron Christensen writes: >> > I am running the following versions of software: >> > >> > Python 3.5 >> > psycopg2==2.6.1 >> > Postgres 9.4.5 >> > >>

Re: Psycopg2 to create a record using a FK

2016-03-12 Thread Aaron Christensen
On Sat, Mar 12, 2016 at 5:03 AM, dieter wrote: > Aaron Christensen writes: > > I am running the following versions of software: > > > > Python 3.5 > > psycopg2==2.6.1 > > Postgres 9.4.5 > > > > I have 2 tables. Table User has UserId (serial PK), LastName, FirstName, > > Gender, DateOfBirth, and

Re: Psycopg2 to create a record using a FK

2016-03-12 Thread Aaron Christensen
On Sat, Mar 12, 2016 at 5:26 AM, Peter Otten <__pete...@web.de> wrote: > Aaron Christensen wrote: > > > Hello, > > > > I am running the following versions of software: > > > > Python 3.5 > > psycopg2==2.6.1 > > Postgres 9.4.5 > > > > I have 2 tables. Table User has UserId (serial PK), LastName, F

Re: Psycopg2 to create a record using a FK

2016-03-12 Thread Peter Otten
Aaron Christensen wrote: > Hello, > > I am running the following versions of software: > > Python 3.5 > psycopg2==2.6.1 > Postgres 9.4.5 > > I have 2 tables. Table User has UserId (serial PK), LastName, FirstName, > Gender, DateOfBirth, and DateEnrolled. Table UserProfile has > UserProfileId

Re: Psycopg2 to create a record using a FK

2016-03-12 Thread dieter
Aaron Christensen writes: > I am running the following versions of software: > > Python 3.5 > psycopg2==2.6.1 > Postgres 9.4.5 > > I have 2 tables. Table User has UserId (serial PK), LastName, FirstName, > Gender, DateOfBirth, and DateEnrolled. Table UserProfile has UserProfileId > (serial, PK),

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-09-01 Thread andydtaylor
Mark - it's more that I just didn't understand what you mean. Here's you: Probably an out and out programmer; uses a number of languages; a decade of experience, educated in best practice via your experience. Here's me: Idiot. A decade of experience in VBA and Excel in mindless finance jobs, h

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-09-01 Thread Mark Lawrence
On 01/09/2014 13:32, andydtay...@gmail.com wrote: Posting style point taken. Google groups doesn't exactly help you with that. Thunderbird is as good a solution as any although there are plenty of other choices. * Statements like "Please equip yourself with a tool that provides us with som

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-09-01 Thread Chris Angelico
On Mon, Sep 1, 2014 at 10:32 PM, wrote: > Posting style point taken. Google groups doesn't exactly help you with that. > > * You guys have probably been tinkering with this stuff for years. I haven't. > * Your man on the street would say I described the error fairly well. > * It's not like I wasn

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-09-01 Thread Andrea D'Amore
On 2014-09-01 12:32:38 +, andydtay...@gmail.com said: Google groups doesn't exactly help you with that. Drop it, get a usenet client or subscribe the mailing list (the newsgroup and the ml are bridged IIRC). * Your man on the street would say I described the error fairly well. That m

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-09-01 Thread andydtaylor
Posting style point taken. Google groups doesn't exactly help you with that. * You guys have probably been tinkering with this stuff for years. I haven't. * Your man on the street would say I described the error fairly well. * It's not like I wasn't trying my best to fix it myself * So far as e

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-09-01 Thread Andrea D'Amore
You make hard to follow your messages both by sending lot of messages and not using an adequate quoting. Please pick a posting style [1] (possibly interleaved) and stick to it. On 2014-08-31 23:35:09 +, andydtay...@gmail.com said: Andrea - yes I am using the virtualenv interpreter as the Pyc

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread Mark Lawrence
On 01/09/2014 00:57, andydtay...@gmail.com wrote: FYI My mac version is Mavericks 10.9.4 Please equip yourself with a tool that provides us with some context. There's not much that we can make out of the one line you give above. -- My fellow Pythonistas, ask not what our language can do for

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread andydtaylor
I have gone ahead and set it all up by using pip install psycopg2 but I would still like to determine why Pycharm couldn't find the $PATH variable -- https://mail.python.org/mailman/listinfo/python-list

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread andydtaylor
FYI My mac version is Mavericks 10.9.4 -- https://mail.python.org/mailman/listinfo/python-list

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread andydtaylor
Chris- I have removed the second copy of postgres I had (postgres.app) and updated path variables in .bash_profile: export PATH=$PATH:/usr/local/share/python export PATH=$PATH:/usr/local/bin export PYTHONPATH=$PYTHONPATH:/usr/local/bin/python export PATH=$PATH:/usr/local/Cellar/postgresql/9

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread andydtaylor
Chris- I have removed the second copy of postgres I had (postgres.app) and updated path variables in .bash_profile: export PATH=$PATH:/usr/local/share/python export PATH=$PATH:/usr/local/bin export PYTHONPATH=$PYTHONPATH:/usr/local/bin/python export PATH=$PATH:/usr/local/Cellar/postgresql/9.3.5_

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread Andrea D'Amore
On 2014-08-31 14:19:24 +, andydtay...@gmail.com said: - Installing to a virtualenv python environment. Are you using the virtualenv interpreter as the Pycharm project interpreter? -- Andrea -- https://mail.python.org/mailman/listinfo/python-list

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread Chris “Kwpolska” Warrick
On Sun, Aug 31, 2014 at 4:19 PM, wrote: > Hi, > > I have a puzzle, for which I would appreciate your opinion on! That’s not much of a puzzle (a game, toy, or problem designed to test ingenuity or knowledge, as defined by Oxford American College Dictionary via http://google.com/search?q=define+pu

Re: Psycopg2 package installation puzzle in Pycharm - any thoughts?

2014-08-31 Thread andydtaylor
Actually I realise that postgres app didn't come from brew I wonder if that's the issue On Sunday, 31 August 2014 15:19:24 UTC+1, andyd...@gmail.com wrote: > Hi, > > > > I have a puzzle, for which I would appreciate your opinion on! > > > > I have been trying to setup a project in Pych

Re: Psycopg2 : error message.

2014-05-19 Thread Tim Roberts
dandrigo wrote: > >I'm writing a python script for a web service. I have to connect to my >postgres/postgis databases via Psycopg2. > >I writed a little first script just to connect to my pg/postgis db and drop >a test db. > >But when i execute the python file, i have several error messages. R

Re: Psycopg2 : error message.

2014-05-16 Thread Chris Angelico
On Fri, May 16, 2014 at 8:18 PM, dandrigo wrote: > Please read the 2 usefull files below : > > Dandrigo pg_test.py > > SS_dos.JPG These would be MUCH better included inline. Please, i

Re: psycopg2 craziness

2013-02-21 Thread Chris Angelico
On Fri, Feb 22, 2013 at 10:27 AM, wrote: cursor_to.execute("CREATE TABLE foo (id serial PRIMARY KEY);") Like many things, it's silent when everything works. As MRAB suggested, you probably need to commit before the changes become visible; unlike certain other database engines, PostgreSQL ac

Re: psycopg2 craziness

2013-02-21 Thread andydtaylor
I'd actually forgotten about commit, thanks! I'll have another go with this in mind. -- http://mail.python.org/mailman/listinfo/python-list

Re: psycopg2 craziness

2013-02-21 Thread MRAB
On 2013-02-21 23:27, andydtay...@gmail.com wrote: Hi, I'm trying to use psycopg2 but having some issues. Would it be possible to get some pointers? I seem unable to execute any SQL statements. So here are my database tables before (and after) I try to do anything: postgres=# \c You are now

Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread Mitya Sirenef
On Wed 09 Jan 2013 09:20:10 PM EST, andydtay...@gmail.com wrote: Thanks for your help guys. I was actually doing a few things wrong, but I have got this script to work by declaring fields as varchar and all values as strings. But I would like to log journey time values in hours/minutes, so I w

Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread andydtaylor
Thanks for your help guys. I was actually doing a few things wrong, but I have got this script to work by declaring fields as varchar and all values as strings. But I would like to log journey time values in hours/minutes, so I will have to look into the following: 1. Retrieving this data from

Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread MRAB
On 2013-01-10 00:19, andydtay...@gmail.com wrote: Hi John, He're the code I would like to see work. The cursor_to is an oversight. I extracted this element from some other code in an attempt to isolate/resolve the problem myself, hence having a simplified table version. Which works actually,

Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread Mitya Sirenef
On Wed 09 Jan 2013 07:19:10 PM EST, andydtay...@gmail.com wrote: Hi John, He're the code I would like to see work. The cursor_to is an oversight. I extracted this element from some other code in an attempt to isolate/resolve the problem myself, hence having a simplified table version. Which wo

Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread andydtaylor
Hi John, He're the code I would like to see work. The cursor_to is an oversight. I extracted this element from some other code in an attempt to isolate/resolve the problem myself, hence having a simplified table version. Which works actually, but unfortunately that's not educating me suffiecien

Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread John Gordon
In andydtay...@gmail.com writes: > I'm a bit stuck on this "INSERT INTO" syntax error. I have no idea why it's What syntax error? It's always helpful if you can post the actual error message. > not working actually... I've tried changing column types to char but that > didn't work. I've gone

Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Walter Hurry
On Sun, 06 Jan 2013 16:44:47 -0500, Mitya Sirenef wrote: > On Sun 06 Jan 2013 04:38:29 PM EST, andydtay...@gmail.com wrote: >> Hi all, >> >> I'm trying to create a process which will create a new table and >> populate it. >> >> But something is preventing this from working, and I don't know enough

Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 9:14 AM, Mitya Sirenef wrote: > On Sun 06 Jan 2013 04:53:32 PM EST, andydtay...@gmail.com wrote: >> >> Wow it's as simple as that! I'm afraid my database experience is in >> Microsoft Access in Windows and not at the command line, so that wasn't >> intuitive for me. >> > IIR

Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Mitya Sirenef
On Sun 06 Jan 2013 04:53:32 PM EST, andydtay...@gmail.com wrote: Wow it's as simple as that! I'm afraid my database experience is in Microsoft Access in Windows and not at the command line, so that wasn't intuitive for me. Thanks again, Andy IIRC I made the same mistake when I was using psy

Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread andydtaylor
Wow it's as simple as that! I'm afraid my database experience is in Microsoft Access in Windows and not at the command line, so that wasn't intuitive for me. Thanks again, Andy -- http://mail.python.org/mailman/listinfo/python-list

Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Chris Angelico
On Mon, Jan 7, 2013 at 8:38 AM, wrote: > But something is preventing this from working, and I don't know enough to > figure it out, despite having spent most of today reading up. The code > executes with no error, yet no table is created or populated. Standard databasing requirement: You need

Re: psycopg2 cursor.execute CREATE TABLE issue

2013-01-06 Thread Mitya Sirenef
On Sun 06 Jan 2013 04:38:29 PM EST, andydtay...@gmail.com wrote: Hi all, I'm trying to create a process which will create a new table and populate it. But something is preventing this from working, and I don't know enough to figure it out, despite having spent most of today reading up. The cod

Re: psycopg2 for insertion of binary data to PostgreSQL database

2010-08-23 Thread Graeme Glass
On Aug 23, 9:37 am, Julia Jacobson wrote: > How can I assign the result of a SQL query to a variable? > The following code snippet doesn't work: > query_result=cur.execute("SELECT column_name FROM table_name WHERE > my_variable = 'my_value'",) > >  > Thomas Jollans wrote: > > > > > * get the recor

Re: psycopg2 for insertion of binary data to PostgreSQL database

2010-08-23 Thread Peter Otten
Julia Jacobson wrote: > How can I assign the result of a SQL query to a variable? > The following code snippet doesn't work: > query_result=cur.execute("SELECT column_name FROM table_name WHERE > my_variable = 'my_value'",) To retrieve an image from a table "images" by its name you could do (unt

Re: psycopg2 for insertion of binary data to PostgreSQL database

2010-08-23 Thread Julia Jacobson
How can I assign the result of a SQL query to a variable? The following code snippet doesn't work: query_result=cur.execute("SELECT column_name FROM table_name WHERE my_variable = 'my_value'",) > Thomas Jollans wrote: * get the record you're interested in -- http://mail.python.org/mailman/li

Re: psycopg2 for insertion of binary data to PostgreSQL database

2010-08-22 Thread Thomas Jollans
On Sunday 22 August 2010, it occurred to Julia Jacobson to exclaim: > Thanks a lot, this was the solution. > It would be greate, if you could also show me a way to extract the > inserted binary object from the table on the server to a file on a client. Probably something along the lines of: * exe

Re: psycopg2 for insertion of binary data to PostgreSQL database

2010-08-22 Thread Julia Jacobson
Thanks a lot, this was the solution. It would be greate, if you could also show me a way to extract the inserted binary object from the table on the server to a file on a client. > Peter Otten wrote: Julia Jacobson wrote: Hello everybody out there using python, For the insertion of pictures

Re: psycopg2 for insertion of binary data to PostgreSQL database

2010-08-21 Thread Peter Otten
Julia Jacobson wrote: > Hello everybody out there using python, > > For the insertion of pictures into my PostgreSQL database [with table > foo created by SQL command "CREATE TABLE foo (bmp BYTEA)], I've written > the following script: > > #!/usr/bin/python > import psycopg2 > try: > conn =

Re: psycopg2 for insertion of binary data to PostgreSQL database

2010-08-21 Thread D'Arcy J.M. Cain
On Sat, 21 Aug 2010 22:58:00 +0200 Julia Jacobson wrote: > For the insertion of pictures into my PostgreSQL database [with table > foo created by SQL command "CREATE TABLE foo (bmp BYTEA)], I've written > the following script: > > #!/usr/bin/python > import psycopg2 > try: > conn = psycopg

Re: psycopg2 / psycopg2.ProgrammingError: syntax error at or near "E'mytable'"

2010-04-05 Thread mrdrew
Thanks for the replies. The param style is pyformat. I've tried using the '%s' style with a set and get exactly the same error. c.execute('SELECT * FROM %s LIMIT 1',('mytable',)) psycopg2.ProgrammingError: syntax error at or near "E'mytable'" LINE 1: SELECT * FROM E'mytable' LIMIT 1 MRAB and St

Re: psycopg2 / psycopg2.ProgrammingError: syntax error at or near "E'mytable'"

2010-04-02 Thread Steve Holden
mrdrew wrote: > Hey all, > > Right now I'm completely unable to pass parameters to queries under > any circumstances. I've got a fairly trivial query as a test... > > c.execute('SELECT * FROM %(table_name)s LIMIT 1', > {'table_name':"mytable"}) > > It fails, giving the error message... > > Tra

Re: psycopg2 / psycopg2.ProgrammingError: syntax error at or near "E'mytable'"

2010-04-02 Thread Tim Chase
MRAB wrote: I think that you're confusing Python's string formatting with SQL placeholders. The "%(table_name)s" works only with Python's '%' operator. You should use only the "%s" form (or possibly "?", I'm not sure which!) It varies depending on your DB driver. Check out the .paramstyle

Re: psycopg2 / psycopg2.ProgrammingError: syntax error at or near "E'mytable'"

2010-04-02 Thread MRAB
mrdrew wrote: Hey all, Right now I'm completely unable to pass parameters to queries under any circumstances. I've got a fairly trivial query as a test... c.execute('SELECT * FROM %(table_name)s LIMIT 1', {'table_name':"mytable"}) It fails, giving the error message... Traceback (most recent

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-31 Thread Anton Shishkov
On Mar 31, 11:29 am, Michael Ricordeau wrote: > Hi > > You cannot add 'NOW() - '29 days'::INTERVAL' as a query because > cursor.execute() will try to mogrify it. > > You can do : >   import datetime >   idays = psycopg2.extensions.adapt(datetime.timedelta(days=29)) >   self.dyndb.orderdb.query('u

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-31 Thread Anton Shishkov
On Mar 31, 3:10 am, "D'Arcy J.M. Cain" wrote: > On Tue, 30 Mar 2010 15:46:12 -0700 (PDT) > > ASh wrote: > > > >             new_start_date = "NOW() - '29 days'::INTERVAL" > > > >             self.dyndb.orderdb.query('''update set creation_date > > > > = %s > > > >             where id_order

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-31 Thread Michael Ricordeau
Hi You cannot add 'NOW() - '29 days'::INTERVAL' as a query because cursor.execute() will try to mogrify it. You can do : import datetime idays = psycopg2.extensions.adapt(datetime.timedelta(days=29)) self.dyndb.orderdb.query('update set creation_date=(NOW() - %s) where id_order=%s',

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-30 Thread D'Arcy J.M. Cain
On Tue, 30 Mar 2010 15:46:12 -0700 (PDT) ASh wrote: > > >             new_start_date = "NOW() - '29 days'::INTERVAL" > > >             self.dyndb.orderdb.query('''update set creation_date > > > = %s > > >             where id_order = %s''', (new_start_date, "123")) > > > > Put single quotes a

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-30 Thread Steve Holden
D'Arcy J.M. Cain wrote: > On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) > ASh wrote: >> Hi, please help me understand why am I getting error with this query >> >> >> new_start_date = "NOW() - '29 days'::INTERVAL" >> self.dyndb.orderdb.query('''update set creation_date >> =

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-30 Thread ASh
On Mar 31, 12:50 am, "D'Arcy J.M. Cain" wrote: > On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) > > ASh wrote: > > Hi, please help me understand why am I getting error with this query > > >             new_start_date = "NOW() - '29 days'::INTERVAL" > >             self.dyndb.orderdb.query('''update xxx

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-30 Thread ASh
On Mar 31, 12:26 am, Philip Semanchuk wrote: > On Mar 30, 2010, at 4:47 PM, ASh wrote: > > > Hi, please help me understand why am I getting error with this query > > >            new_start_date = "NOW() - '29 days'::INTERVAL" > >            self.dyndb.orderdb.query('''update set creation_date

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-30 Thread D'Arcy J.M. Cain
On Tue, 30 Mar 2010 13:47:42 -0700 (PDT) ASh wrote: > Hi, please help me understand why am I getting error with this query > > > new_start_date = "NOW() - '29 days'::INTERVAL" > self.dyndb.orderdb.query('''update set creation_date > = %s > where id_order

Re: psycopg2 / psycopg2.DataError: invalid input syntax for type timestamp with time zone:

2010-03-30 Thread Philip Semanchuk
On Mar 30, 2010, at 4:47 PM, ASh wrote: Hi, please help me understand why am I getting error with this query new_start_date = "NOW() - '29 days'::INTERVAL" self.dyndb.orderdb.query('''update set creation_date = %s where id_order = %s''', (new_start_date,

Re: psycopg2 weirdness

2009-01-19 Thread Yang Zhang
For posterity: the problem turned out to be a second request being made in quick succession by the client-side Javascript, causing the web.py request handler to run in multiple threads concurrently. The request handlers don't create their own Postgresql connections, but instead share one acros

Re: psycopg2 weirdness

2009-01-17 Thread Philip Semanchuk
On Jan 17, 2009, at 12:48 PM, Neha Gupta wrote: Hey, I only have little experience with web.py and psycopg2 and am running into a weird problem, I'd appreciate any help I can get with debugging it. Hi Neha, There's a lot of pieces involved here and your subject implies you've isolated the

Re: psycopg2 weirdness

2009-01-17 Thread Tino Wildenhain
Neha Gupta wrote: Hey, ... crs_dep_hour, origin from flightdata where date = '" + date + "' group ^^^ never ever do that! Even more when input comes from user. The correct form is cur.exec("... date = %s group by ...",(date,)) ple

Re: psycopg2 and large queries

2008-12-18 Thread Laszlo Nagy
They do have a description attribute, but it is only populated after you fetch a row. eg try cur = conn.cursor(name='mycursor') cur.execute('select name from blah') cur.fetchone() print cur.description Oh, great. I should have known. Thanks. Maybe I can live with psycopg2, because combining

Re: psycopg2 and large queries

2008-12-18 Thread alito
On Dec 19, 2:34 am, Laszlo Nagy wrote: > > I was looking for psycopg2 documentation, but I found nothing. However, > I found some posts telling that named cursors do support fetching a > single row at a time. Here is how to create a named cursor: > > cur = conn.cursor('mycursor') > > This is very

Re: psycopg2 and large queries

2008-12-18 Thread Paul Boddie
On 18 Des, 22:28, Laszlo Nagy wrote: > > I'm just looking for something that can replace psycopg2, because of the > bug mentioned in my original post. Here are my options: > > - psycopg1: development stalled > - psycopg2: memory bug and/or not db api compilant (see my original post) If you want,

  1   2   >