Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Postgresql type casting (ex: column::datatype) creates an exception #15

Open
niparis opened this issue Dec 20, 2017 · 5 comments
Open

Comments

@niparis
Copy link

niparis commented Dec 20, 2017

using the following query :

SELECT creationtime::date, name
FROM question.questionnaires
ORDER BY creationtime DESC;

will give the following exception: TypeError: tuple indices must be integers or slices, not str

because anosql will internally change the sql to :

SELECT creationtime:%(date)s, name 
FROM question.questionnaires 
ORDER BY creationtime DESC;
@alysbrooks
Copy link
Contributor

I think I wrote the code responsible, so I can take a look this weekend. :)

@taidan19
Copy link
Contributor

Ran into this one myself. It was rather curious, because the regex responsible for this in the anoaql code looks like this:

re.sub(r':([a-zA-Z_-]+)', r'%(\1)s', query)

I thought it was rather curious, as I wasn't sure what it's purpose was for. The only time I've ever seen a single colon used in Postgres is for array slicing.

taidan19 added a commit to taidan19/anosql that referenced this issue Jan 26, 2018
taidan19 added a commit to taidan19/anosql that referenced this issue Jan 26, 2018
Proposed fix for bug found in honza#15.
@alysbrooks
Copy link
Contributor

If I remember correctly, using a colon before a name is an anosql convention for parameters (maybe adopted from yesql?) that are being inserted from Python. E.g., WHERE user = :username would make :username a keyword argument in the generated function.

@honza
Copy link
Owner

honza commented Jan 31, 2018

I merged the fix. Would you mind testing it?

@nackjicholson
Copy link
Collaborator

We should check this against the big regex PR I had merged #25

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants