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 looking into using Azure but I'm having some issues getting
I have recently started using Vim as my text editor and am currently working
I have recently started working on a very large C++ project that, after completing
I have recently started looking into Google Charts API for possible use within the
I have recently started using CAML.NET IntelliSense for SharePoint with Visual Studio 2008; which
I have recently started using Google Webmaster Tools . I was quite surprised to
We have recently started using git and had a nasty problem when someone committed
I have recently started using DocCheck for checking the validity of JavaDoc's in code
I have recently started using Zend Framework. I started developing on my local XAMPP

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.