From: Timothy S. <ti...@op...> - 2004-11-26 04:37:04
|
is there another way to provide arguements to a query besides tuples? eg. cur.excute("Select %s from table", (column)) becuase tuples cannot grow or shrink this is VERY limiting, i am in a situation right now where i need to select a range of days of week, because the length might change using a tuple is a pain. |
From: Gerhard H. <gh...@gh...> - 2004-11-26 08:40:01
|
On Fri, Nov 26, 2004 at 02:36:55PM +1000, Timothy Smith wrote: > is there another way to provide arguements to a query besides tuples? eg. > cur.excute("Select %s from table", (column)) > becuase tuples cannot grow or shrink this is VERY limiting, i am in a=20 > situation right now where i need to select a range of days of week,=20 > because the length might change using a tuple is a pain. The second argument to execute() must be a sequence. You can use tuples, or lists, for example. -- Gerhard |
From: Karsten H. <Kar...@gm...> - 2004-11-28 10:00:39
|
> > is there another way to provide arguements to a query besides tuples? eg. > > cur.excute("Select %s from table", (column)) > > becuase tuples cannot grow or shrink this is VERY limiting, i am in a > > situation right now where i need to select a range of days of week, > > because the length might change using a tuple is a pain. > > The second argument to execute() must be a sequence. You can use tuples, or > lists, for example. Be weary of one-element sequences, though. They tend to be troublesome. The trick we tend to use is if len(seq) == 1: seq.append(seq[0]) BTW, I am not sure you are intended to do "select %s from table", (column) The query arguments are intended to be values for the *where* clause, no ? Karsten -- GPG key ID E4071346 @ wwwkeys.pgp.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 |
From: Chuck B. <cfb...@gm...> - 2004-11-29 16:17:18
|
On Sun, 28 Nov 2004 10:42:12 +0100, Karsten Hilbert <kar...@gm...> wrote: [...] > The query arguments are intended to be values for the *where* > clause, no ? I am inclined to agree with Karsten that query arguments are for the WHERE clause. To insert the names of columns to be retrieved into a SELECT statement at runtime, I would use Python string formatting and a helper function that returns a tuple of days of the week: def daysOfWeek(): <build list 'L' with range of days> return tuple(L) [...] cur.excute("Select %s from table" % (daysOfWeek())) Chuck |
From: Timothy S. <ti...@op...> - 2004-11-29 21:19:35
|
I've already solved this, but. sql gives you so many abilities, why should you be limited to providing aruguement to a single clause? it really is very limiting. theres no way to provide a variable list of arguements to your query. Chuck Bearden wrote: >On Sun, 28 Nov 2004 10:42:12 +0100, Karsten Hilbert ><kar...@gm...> wrote: >[...] > > >>The query arguments are intended to be values for the *where* >>clause, no ? >> >> > >I am inclined to agree with Karsten that query arguments are for the >WHERE clause. To insert the names of columns to be retrieved into a >SELECT statement at runtime, I would use Python string formatting and >a helper function that returns a tuple of days of the week: > >def daysOfWeek(): > <build list 'L' with range of days> > return tuple(L) >[...] >cur.excute("Select %s from table" % (daysOfWeek())) > >Chuck > > >------------------------------------------------------- >SF email is sponsored by - The IT Product Guide >Read honest & candid reviews on hundreds of IT Products from real users. >Discover which products truly live up to the hype. Start reading now. >http://productguide.itmanagersjournal.com/ >_______________________________________________ >Pypgsql-users mailing list >Pyp...@li... >https://lists.sourceforge.net/lists/listinfo/pypgsql-users > > > > |
From: Billy G. A. <bil...@mu...> - 2004-11-29 07:45:14
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Timothy Smith wrote: | is there another way to provide arguements to a query besides tuples? eg. | cur.excute("Select %s from table", (column)) | becuase tuples cannot grow or shrink this is VERY limiting, i am in a | situation right now where i need to select a range of days of week, | because the length might change using a tuple is a pain. | | | ------------------------------------------------------- | SF email is sponsored by - The IT Product Guide | Read honest & candid reviews on hundreds of IT Products from real users. | Discover which products truly live up to the hype. Start reading now. | http://productguide.itmanagersjournal.com/ | _______________________________________________ | Pypgsql-users mailing list | Pyp...@li... | https://lists.sourceforge.net/lists/listinfo/pypgsql-users | You can just list them in the query command: cur.execute(<query string>, arg1, arg2, ...) You can provide a list or a tupple containing the parameters (Note, when providing the areguments as a list or tupple, it must be the only areument after the query striing). - -- ____ | Billy G. Allie | Domain....: Bil...@mu... | /| | 7436 Hartwell | MSN.......: B_G...@em... |-/-|----- | Dearborn, MI 48126| |/ |LLIE | (313) 582-1540 | -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFBqtOFnmIkMXoVVdURArRgAKDynI56zsqK3kfOtVcB6EELovL6UACdGQP5 54AqNkekj2AUvhocDVA79DY= =9Syk -----END PGP SIGNATURE----- |