Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5935801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:18:25+00:00 2026-05-22T15:18:25+00:00

I have recently started using SQLALCHEMY to query a my-sql database. I want to

  • 0

I have recently started using SQLALCHEMY to query a my-sql database. I want to generate a select statement that uses the “INTO OUTFILE <file>” syntax to export query results to a test file. For example:

SELECT *
FROM table
INTO OUTFILE '/tmp/export.txt';

Is there a way to generate the “INTO OUTFILE...” clause using SQLALCHEMY?

If not, can I subclass one of the SQLALCHEMY classes so I can build that clause myself?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:18:25+00:00Added an answer on May 22, 2026 at 3:18 pm

    I did some thinking and poking around the examples on the SQLAlchemy site and figured it out. (Also posted to sql-alchemy user reciptes)


    from sqlalchemy import *
    from sqlalchemy.sql.expression import Executable, ClauseElement
    from sqlalchemy.ext import compiler
    
    class SelectIntoOutfile(Executable, ClauseElement):
        def __init__(self, select, file):
            self.select = select
            self.file = file
    
    
    @compiler.compiles(SelectIntoOutfile)
    def compile(element, compiler, **kw):
        return "%s INTO OUTFILE '%s'" % (
            compiler.process(element.select), element.file
        )
    
    
    e = SelectIntoOutfile(select([s.dim_date_table]).where(s.dim_date_table.c.Year==2009), '/tmp/test.txt')
    print e
    eng.execute(e)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started using generics in java, and in that attempt tried to
I have recently started using ASP.Net MVC 3 RC 2 and have attempted to
I have recently started using Visual studio 2010 ,so I'm unaware of its various
I have recently started using Visual Studio 2010 and ReSharper 5.1. It's working pretty
I have just recently started using NetBeans IDE (6.9.1) and have used it to
I have only fairly recently started using Maven (2.2.1), and I have Artifactory running
I have recently started testing for my android application using Instrumentation framework. I have
I've recently started using ctags on my projects. I currently have the following setup:
I've recently started using boost. So far most things have been pretty straight forward.
I have been stuck on this for a day or two, I have recently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.