Re: [sqlalchemy] custom queries

2016-01-13 Thread Mike Bayer
sure, use pdb to step through and use the "where" command to show where
each call originates.

alternatively, if this is for profiling, you can use print_callers() as
in the example at
http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling which
will show the origins of calls, though you'd need to step through things
to see the full chain.  A tool like RunSnakeRun can provide a graphical
display instead.


On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:
> hi all!
> 
> i'm wondering if there's a way to determinate if a query was "launch" by
> my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
> (backref, relationship, etc). i think it's better to use a example,
> based on *adjacency_list.py*:
> 
> http://pastebin.com/q3yx36vn
> 
> in the code, you'll notice there's only one query *literally* written
> (in the main script), but "STEP" is called more than once (by
> internals). my question is: can I differ between them?
> 
> thanks a lot!
> richard.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> .
> To post to this group, send email to sqlalchemy@googlegroups.com
> .
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] custom queries

2016-01-13 Thread Richard Gerd Kuesters
Mike, thanks for your attention and i'm sorry, i was not clear enough in 
my question.


i would like to know if there's a way to tell if a query was fired by 
sqlalchemy internals or by my coded query (programatically).



thanks a lot!
richard.

On 01/13/2016 04:11 PM, Mike Bayer wrote:

sure, use pdb to step through and use the "where" command to show where
each call originates.

alternatively, if this is for profiling, you can use print_callers() as
in the example at
http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling which
will show the origins of calls, though you'd need to step through things
to see the full chain.  A tool like RunSnakeRun can provide a graphical
display instead.


On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:

hi all!

i'm wondering if there's a way to determinate if a query was "launch" by
my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
(backref, relationship, etc). i think it's better to use a example,
based on *adjacency_list.py*:

http://pastebin.com/q3yx36vn

in the code, you'll notice there's only one query *literally* written
(in the main script), but "STEP" is called more than once (by
internals). my question is: can I differ between them?

thanks a lot!
richard.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
.
To post to this group, send email to sqlalchemy@googlegroups.com
.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] custom queries

2016-01-13 Thread Richard Gerd Kuesters
yup! i already was going this way. it would be impossible to 
"automagically" do this without the performance sacrifice ... lol. well, 
if this looks reasonable in some use cases, can this sort of "feature" 
be implemented in future sa releases?


best regards,
richard.

On 01/13/2016 04:41 PM, Mike Bayer wrote:

or, place a marker in your own queries:

query(User).execution_options(my_query=True).all()



On 01/13/2016 01:40 PM, Mike Bayer wrote:


similar, you'd need to use sys.exc_info() and walk through the stack
trace to programmatically determine the origin of a Python statement.
You could do this inside the before_execute() event, for example.




On 01/13/2016 01:31 PM, Richard Gerd Kuesters wrote:

Mike, thanks for your attention and i'm sorry, i was not clear enough in
my question.

i would like to know if there's a way to tell if a query was fired by
sqlalchemy internals or by my coded query (programatically).


thanks a lot!
richard.

On 01/13/2016 04:11 PM, Mike Bayer wrote:

sure, use pdb to step through and use the "where" command to show where
each call originates.

alternatively, if this is for profiling, you can use print_callers() as
in the example at
http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling which
will show the origins of calls, though you'd need to step through things
to see the full chain.  A tool like RunSnakeRun can provide a graphical
display instead.


On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:

hi all!

i'm wondering if there's a way to determinate if a query was "launch" by
my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
(backref, relationship, etc). i think it's better to use a example,
based on *adjacency_list.py*:

http://pastebin.com/q3yx36vn

in the code, you'll notice there's only one query *literally* written
(in the main script), but "STEP" is called more than once (by
internals). my question is: can I differ between them?

thanks a lot!
richard.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
.
To post to this group, send email to sqlalchemy@googlegroups.com
.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
.
To post to this group, send email to sqlalchemy@googlegroups.com
.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>

Re: [sqlalchemy] custom queries

2016-01-13 Thread Mike Bayer
I can't imagine what such a "feature" would look like nor how it
wouldn't require every call everywhere in SQLA internals  well as all
dialects, 3rd party and otherwise, to always remember to mark itself in
some way, annotating the end-user statement as I illustrated is already
available now.

as


On 01/13/2016 01:46 PM, Richard Gerd Kuesters wrote:
> yup! i already was going this way. it would be impossible to
> "automagically" do this without the performance sacrifice ... lol. well,
> if this looks reasonable in some use cases, can this sort of "feature"
> be implemented in future sa releases?
> 
> best regards,
> richard.
> 
> On 01/13/2016 04:41 PM, Mike Bayer wrote:
>> or, place a marker in your own queries:
>>
>> query(User).execution_options(my_query=True).all()
>>
>>
>>
>> On 01/13/2016 01:40 PM, Mike Bayer wrote:
>>>
>>> similar, you'd need to use sys.exc_info() and walk through the stack
>>> trace to programmatically determine the origin of a Python statement.
>>> You could do this inside the before_execute() event, for example.
>>>
>>>
>>>
>>>
>>> On 01/13/2016 01:31 PM, Richard Gerd Kuesters wrote:
 Mike, thanks for your attention and i'm sorry, i was not clear enough in
 my question.

 i would like to know if there's a way to tell if a query was fired by
 sqlalchemy internals or by my coded query (programatically).


 thanks a lot!
 richard.

 On 01/13/2016 04:11 PM, Mike Bayer wrote:
> sure, use pdb to step through and use the "where" command to show where
> each call originates.
>
> alternatively, if this is for profiling, you can use print_callers() as
> in the example at
> http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling 
> which
> will show the origins of calls, though you'd need to step through things
> to see the full chain.  A tool like RunSnakeRun can provide a graphical
> display instead.
>
>
> On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:
>> hi all!
>>
>> i'm wondering if there's a way to determinate if a query was "launch" by
>> my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
>> (backref, relationship, etc). i think it's better to use a example,
>> based on *adjacency_list.py*:
>>
>> http://pastebin.com/q3yx36vn
>>
>> in the code, you'll notice there's only one query *literally* written
>> (in the main script), but "STEP" is called more than once (by
>> internals). my question is: can I differ between them?
>>
>> thanks a lot!
>> richard.
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to sqlalchemy+unsubscr...@googlegroups.com
>> .
>> To post to this group, send email to sqlalchemy@googlegroups.com
>> .
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
 -- 
 You received this message because you are subscribed to the Google
 Groups "sqlalchemy" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to sqlalchemy+unsubscr...@googlegroups.com
 .
 To post to this group, send email to sqlalchemy@googlegroups.com
 .
 Visit this group at https://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> .
> To post to this group, send email to sqlalchemy@googlegroups.com
> .
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] using mysql user variables

2016-01-13 Thread yoch . melka
Hello,

I want to compute difference between successive records.
In MySQL, I had written something like : 

SET @prev := 0;
SELECT time_to_sec(@prev), @prev := ts FROM mytable;

How to achieve the same with sqlalchemy ?
(I prefer to do it in SQL rather than python because I want to aggregate 
the results)

Best regards

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] using mysql user variables

2016-01-13 Thread Mike Bayer
it would depend upon if this can be done within a single
cursor.execute() or if it would require multiple invocations.

At the very least, if the DBAPI that you're using can support it, I'd
start with direct cursor access as illustrated at
http://docs.sqlalchemy.org/en/rel_1_0/core/connections.html#working-with-raw-dbapi-connections.
 if the DBAPI can't support it then SQLAlchemy could not do it either.





On 01/13/2016 03:07 PM, yoch.me...@gmail.com wrote:
> Hello,
> 
> I want to compute difference between successive records.
> In MySQL, I had written something like : 
> 
> |
> SET @prev:=0;
> SELECT time_to_sec(@prev),@prev:=ts FROM mytable;
> |
> 
> How to achieve the same with sqlalchemy ?
> (I prefer to do it in SQL rather than python because I want to aggregate
> the results)
> 
> Best regards
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> .
> To post to this group, send email to sqlalchemy@googlegroups.com
> .
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] custom queries

2016-01-13 Thread Mike Bayer


similar, you'd need to use sys.exc_info() and walk through the stack
trace to programmatically determine the origin of a Python statement.
You could do this inside the before_execute() event, for example.




On 01/13/2016 01:31 PM, Richard Gerd Kuesters wrote:
> Mike, thanks for your attention and i'm sorry, i was not clear enough in
> my question.
> 
> i would like to know if there's a way to tell if a query was fired by
> sqlalchemy internals or by my coded query (programatically).
> 
> 
> thanks a lot!
> richard.
> 
> On 01/13/2016 04:11 PM, Mike Bayer wrote:
>> sure, use pdb to step through and use the "where" command to show where
>> each call originates.
>>
>> alternatively, if this is for profiling, you can use print_callers() as
>> in the example at
>> http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling 
>> which
>> will show the origins of calls, though you'd need to step through things
>> to see the full chain.  A tool like RunSnakeRun can provide a graphical
>> display instead.
>>
>>
>> On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:
>>> hi all!
>>>
>>> i'm wondering if there's a way to determinate if a query was "launch" by
>>> my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
>>> (backref, relationship, etc). i think it's better to use a example,
>>> based on *adjacency_list.py*:
>>>
>>> http://pastebin.com/q3yx36vn
>>>
>>> in the code, you'll notice there's only one query *literally* written
>>> (in the main script), but "STEP" is called more than once (by
>>> internals). my question is: can I differ between them?
>>>
>>> thanks a lot!
>>> richard.
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "sqlalchemy" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to sqlalchemy+unsubscr...@googlegroups.com
>>> .
>>> To post to this group, send email to sqlalchemy@googlegroups.com
>>> .
>>> Visit this group at https://groups.google.com/group/sqlalchemy.
>>> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> .
> To post to this group, send email to sqlalchemy@googlegroups.com
> .
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] custom queries

2016-01-13 Thread Mike Bayer
or, place a marker in your own queries:

query(User).execution_options(my_query=True).all()



On 01/13/2016 01:40 PM, Mike Bayer wrote:
> 
> 
> similar, you'd need to use sys.exc_info() and walk through the stack
> trace to programmatically determine the origin of a Python statement.
> You could do this inside the before_execute() event, for example.
> 
> 
> 
> 
> On 01/13/2016 01:31 PM, Richard Gerd Kuesters wrote:
>> Mike, thanks for your attention and i'm sorry, i was not clear enough in
>> my question.
>>
>> i would like to know if there's a way to tell if a query was fired by
>> sqlalchemy internals or by my coded query (programatically).
>>
>>
>> thanks a lot!
>> richard.
>>
>> On 01/13/2016 04:11 PM, Mike Bayer wrote:
>>> sure, use pdb to step through and use the "where" command to show where
>>> each call originates.
>>>
>>> alternatively, if this is for profiling, you can use print_callers() as
>>> in the example at
>>> http://docs.sqlalchemy.org/en/rel_1_0/faq/performance.html#code-profiling 
>>> which
>>> will show the origins of calls, though you'd need to step through things
>>> to see the full chain.  A tool like RunSnakeRun can provide a graphical
>>> display instead.
>>>
>>>
>>> On 01/13/2016 11:58 AM, Richard Gerd Kuesters wrote:
 hi all!

 i'm wondering if there's a way to determinate if a query was "launch" by
 my code (ex. session.query(Entity)...) or by the internals of sqlalchemy
 (backref, relationship, etc). i think it's better to use a example,
 based on *adjacency_list.py*:

 http://pastebin.com/q3yx36vn

 in the code, you'll notice there's only one query *literally* written
 (in the main script), but "STEP" is called more than once (by
 internals). my question is: can I differ between them?

 thanks a lot!
 richard.

 -- 
 You received this message because you are subscribed to the Google
 Groups "sqlalchemy" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to sqlalchemy+unsubscr...@googlegroups.com
 .
 To post to this group, send email to sqlalchemy@googlegroups.com
 .
 Visit this group at https://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "sqlalchemy" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to sqlalchemy+unsubscr...@googlegroups.com
>> .
>> To post to this group, send email to sqlalchemy@googlegroups.com
>> .
>> Visit this group at https://groups.google.com/group/sqlalchemy.
>> For more options, visit https://groups.google.com/d/optout.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] PostgreSQL domains

2016-01-13 Thread Mike Bayer


On 01/13/2016 12:37 AM, Jonathan Rogers wrote:
> I have several domains based on type TEXT to constrain values in
> specific ways, such as to disallow empty values or only allow valid
> email addresses. When I reflect tables with columns of such a domain,
> SQLAlchemy simply considers their types to be TEXT. Is there any way to
> make the domains known to SQLAlchemy so that it can treat them as
> distinct types? My goal is to define a new table with nearly identical
> structure to an existing one, adding some columns in the process. I
> looked over
> 
> 
>   "Custom Types" in the manual but I wasn't sure where to start. Would I
>   be creating an entirely new type or augmenting an existing one?

This is a Text subtype so I'd have TEXT in the superclass, the @compiles
approach can be used to give it its DDL:

from sqlalchemy.types import TEXT
from sqlalchemy.ext.compiler import compiles

class MyType(TEXT):
pass

@compiles(MyType)
def _mytype(elem, compiler, **kw):
return "MYTYPE"




> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to sqlalchemy+unsubscr...@googlegroups.com
> .
> To post to this group, send email to sqlalchemy@googlegroups.com
> .
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] custom queries

2016-01-13 Thread Richard Gerd Kuesters

hi all!

i'm wondering if there's a way to determinate if a query was "launch" by 
my code (ex. session.query(Entity)...) or by the internals of sqlalchemy 
(backref, relationship, etc). i think it's better to use a example, 
based on *adjacency_list.py*:


http://pastebin.com/q3yx36vn

in the code, you'll notice there's only one query *literally* written 
(in the main script), but "STEP" is called more than once (by 
internals). my question is: can I differ between them?


thanks a lot!
richard.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
<>