Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
String to Column Type Conversion
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tom Burdick  
View profile  
 More options Nov 23 2009, 11:33 am
From: Tom Burdick <thomas.burd...@gmail.com>
Date: Mon, 23 Nov 2009 08:33:18 -0800 (PST)
Local: Mon, Nov 23 2009 11:33 am
Subject: String to Column Type Conversion
I would like to present my users a simple search box that searches a
table.

I have issues getting DataError when using the text input and trying
to do filter against a column that is an integer only column.

I want to have some code that takes a particular sqlalchemy column
object and attempts to convert a string to the column type so that it
can be used for filtering. Is there some way of doing this?

I tried something like... (key word is like here, I know it probably
isn't exactly correct)

myval = '10'
myval = mytable.c.some_id.type(myval)

I get an exception DataError.

I don't really understand how I could do what I want with pure
introspection like I do now.

-Tom


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Burdick  
View profile  
 More options Nov 23 2009, 12:05 pm
From: Tom Burdick <thomas.burd...@gmail.com>
Date: Mon, 23 Nov 2009 09:05:56 -0800 (PST)
Local: Mon, Nov 23 2009 12:05 pm
Subject: Re: String to Column Type Conversion
Ok, here's a small test. It actually works fine when using sqlite, but
not when using postgresql. I want it to work with postgresql!

This probably helps more than the description above.

http://www.pylonshq.com/pasties/fe6a2857f3f72d499914caabce0d41bc

-Tom

On Nov 23, 10:33 am, Tom Burdick <thomas.burd...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Conor  
View profile  
 More options Nov 23 2009, 1:42 pm
From: Conor <conor.edward.da...@gmail.com>
Date: Mon, 23 Nov 2009 12:42:03 -0600
Local: Mon, Nov 23 2009 1:42 pm
Subject: Re: [sqlalchemy] Re: String to Column Type Conversion

You can use sqlalchemy.cast() to coerce the type on the DB side:
coerced_teststr = cast(teststr, column.type)
records = session.query(History).filter(column==coerced_teststr)

-Conor


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas Burdick  
View profile  
 More options Nov 23 2009, 3:07 pm
From: Thomas Burdick <thomas.burd...@gmail.com>
Date: Mon, 23 Nov 2009 14:07:56 -0600
Local: Mon, Nov 23 2009 3:07 pm
Subject: Re: [sqlalchemy] Re: String to Column Type Conversion

This is exactly what I was looking for, thank you.

Tom

On Nov 23, 2009 12:42 PM, "Conor" <conor.edward.da...@gmail.com> wrote:

Tom Burdick wrote: > Ok, here's a small test. It actually works fine when

using sqlite, but > not wh...
You can use sqlalchemy.cast() to coerce the type on the DB side:
coerced_teststr = cast(teststr, column.type)
records = session.query(History).filter(column==coerced_teststr)

-Conor

-- You received this message because you are subscribed to the Google Groups
"sqlalchemy" group. T...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »