Re: Fwd: Timestamp Query Parameters

From: Lutz Steinborn <l(dot)steinborn(at)4c-ag(dot)de>
To: Ari King <ari(dot)brandeis(dot)king(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Fwd: Timestamp Query Parameters
Date: 2014-03-14 05:40:31
Message-ID: 20140314064031.97c27627f30a64a9ee6a149d@4c-ag.de
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: psycopg

On Thu, 13 Mar 2014 17:40:52 -0400
Ari King <ari(dot)brandeis(dot)king(at)gmail(dot)com> wrote:

> Hi,
>
> I'm just starting out with psycopg2. I'm trying to pass a timestamp query
> parameter to an sql query. Unfortunately the constructed query returns
> nothing, even though it should. The code follows; does anyone see what I'm
> doing wrong?
>
> date = datetime.now().strftime("%Y-%m-%d")
> params = [datetime.strptime(date + " 00:00:00", '%Y-%m-%d %H:%M:%S'),
> datetime.s
> trptime(date + " 23:59:59", '%Y-%m-%d %H:%M:%S')]
> print params
> try:
> query = """select * from timesheet
> s where submitted=true and started_at between '%s' and '%s'"""
> cursor.mogrify(query, params)

Found this in the doc:
http://initd.org/psycopg/docs/usage.html#index-9

Looks like you can use Python Date/time objects directly.

Regards

--
Lutz Steinborn
4c Business Service GmbH
Putzbrunner Str. 71
81739 Muenchen

l(dot)steinborn(at)4c-ag(dot)de, http://www.4c-gmbh.de

---------------------------------------------------------
Sitz der Gesellschaft: Putzbrunner Str. 71, 81739 Muenchen
Vertretungsberechtigter Geschaeftsfuehrer: Frank W. Lutze
Registergericht: Amtsgericht Muenchen
Registernummer: HR 130 207
Ustnr. gemaess § 27 a Umsatzsteuergesetz: DE 206 864 106

In response to

Browse psycopg by date

  From Date Subject
Next Message David Fetter 2014-03-14 18:42:16 Server-side prepare and execute
Previous Message Adrian Klaver 2014-03-13 22:32:47 Re: Fwd: Timestamp Query Parameters