librelist archives

« back to archive

how to insert data into main table from two another tables in sqlalchemy?

how to insert data into main table from two another tables in sqlalchemy?

From:
Kundan Singh
Date:
2013-07-12 @ 12:30
I am writing a flask+python application in which i have used **SqlAlchemy**
for database. I have two tables **songs** and **videos** in which data is
stored, its models are:

    class song(db.Model):
        __tablename__ = 'song'
        id = db.Column(db.Integer, primary_key=True)
        songtitle = db.Column(db.Text, nullable=False)
        songurl= db.Column(db.Text, nullable=False)
        songlyrics= db.Column(db.Text, nullable=False)
        songdate =db.Column(db.Date,nullable = False)

       def__init__(#parameters):
          #parameter values


    class video(db.Model):
        __tablename__ = 'video'
        id = db.Column(db.Integer, primary_key=True)
        videotitle = db.Column(db.Text, nullable=False)
        videourl= db.Column(db.Text, nullable=False)
        videolyrics= db.Column(db.Text, nullable=False)
        videodate =db.Column(db.Date,nullable = False)

        def__init__(#parameters):
          #parameter values

And i have another table named **mediafeed** as:



      class mediafeed(db.Model):
            __tablename__ = 'mediafeed'
            id = db.Column(db.Integer, primary_key=True)
            mediafeedtitle = db.Column(db.Text, nullable=False)
            mediafeedurl= db.Column(db.Text, nullable=False)
            mediafeedlyrics= db.Column(db.Text, nullable=False)
            mediafeeddate =db.Column(db.Date,nullable = False)

            def__init__(#parameters):
              #parameter values

Data into **songs** and **videos** tables are added by Users of application
but i need the data stored into **mediafeed** table to be used for other
operations.

the data should be sorted by columns **songdate** and **videodate** and
then it should be entered into the **mediafield** table accordingly on
running a script.

suppose: *video* table data is:
  '1' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
'2013-7-10'
  '2' 'gangam style' 'www.video.us/gangam-style' 'oopm gangam style'
'2013-7-4'

suppose: *song *table data is:
  '1' 'loving you' 'www.song.us/love-you' 'love you forever' '2013-7-5'
  '2' 'let's party' 'www.song.us/let's party' 'let's party tonight'
'2013-7-3'

so i want the data into *mediafeed* table as:
  '1' 'song: let's party' 'www.song.us/let's party' 'let's party tonight'
'2013-7-3'
  '2' 'video: gangam style' 'www.video.us/gangam-style' 'oopm gangam style'
'2013-7-4'
  '3' 'song: loving you' 'www.song.us/love-you' 'love you forever'
'2013-7-5'
  '4' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
'2013-7-10'

My purpose is to write a python method using sqlalchemy functions, so that
i can run it and data into *mediafeed* would be added from other tables as
required.

Please help or suggest. Or provide any specific tutorial link etc.

Thanks
Kundan Singh

Re: [flask] how to insert data into main table from two another tables in sqlalchemy?

From:
Cliff Kachinske
Date:
2013-07-12 @ 13:16
My suggestion is to rethink your design.

If the two blobs are truly the same, it's just a waste of disk space.

Honestly I don't really understand why you need separate tables for songs
and videos.  Blobs are just blobs, after all.  If you need to distinguish
between them, just add a column for media_type and take it from there.


On Fri, Jul 12, 2013 at 8:30 AM, Kundan Singh <ksingh.pilani@gmail.com>wrote:

> I am writing a flask+python application in which i have used
> **SqlAlchemy** for database. I have two tables **songs** and **videos** in
> which data is stored, its models are:
>
>     class song(db.Model):
>         __tablename__ = 'song'
>         id = db.Column(db.Integer, primary_key=True)
>         songtitle = db.Column(db.Text, nullable=False)
>         songurl= db.Column(db.Text, nullable=False)
>         songlyrics= db.Column(db.Text, nullable=False)
>         songdate =db.Column(db.Date,nullable = False)
>
>        def__init__(#parameters):
>           #parameter values
>
>
>     class video(db.Model):
>         __tablename__ = 'video'
>         id = db.Column(db.Integer, primary_key=True)
>         videotitle = db.Column(db.Text, nullable=False)
>         videourl= db.Column(db.Text, nullable=False)
>         videolyrics= db.Column(db.Text, nullable=False)
>         videodate =db.Column(db.Date,nullable = False)
>
>         def__init__(#parameters):
>           #parameter values
>
> And i have another table named **mediafeed** as:
>
>
>
>       class mediafeed(db.Model):
>             __tablename__ = 'mediafeed'
>             id = db.Column(db.Integer, primary_key=True)
>             mediafeedtitle = db.Column(db.Text, nullable=False)
>             mediafeedurl= db.Column(db.Text, nullable=False)
>             mediafeedlyrics= db.Column(db.Text, nullable=False)
>             mediafeeddate =db.Column(db.Date,nullable = False)
>
>             def__init__(#parameters):
>               #parameter values
>
> Data into **songs** and **videos** tables are added by Users of
> application but i need the data stored into **mediafeed** table to be used
> for other operations.
>
> the data should be sorted by columns **songdate** and **videodate** and
> then it should be entered into the **mediafield** table accordingly on
> running a script.
>
> suppose: *video* table data is:
>   '1' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
> '2013-7-10'
>   '2' 'gangam style' 'www.video.us/gangam-style' 'oopm gangam style'
> '2013-7-4'
>
> suppose: *song *table data is:
>   '1' 'loving you' 'www.song.us/love-you' 'love you forever' '2013-7-5'
>   '2' 'let's party' 'www.song.us/let's party' 'let's party tonight'
> '2013-7-3'
>
> so i want the data into *mediafeed* table as:
>   '1' 'song: let's party' 'www.song.us/let's party' 'let's party tonight'
> '2013-7-3'
>   '2' 'video: gangam style' 'www.video.us/gangam-style' 'oopm gangam
> style' '2013-7-4'
>   '3' 'song: loving you' 'www.song.us/love-you' 'love you forever'
> '2013-7-5'
>   '4' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
> '2013-7-10'
>
> My purpose is to write a python method using sqlalchemy functions, so that
> i can run it and data into *mediafeed* would be added from other tables
> as required.
>
> Please help or suggest. Or provide any specific tutorial link etc.
>
> Thanks
> Kundan Singh
>

Re: [flask] how to insert data into main table from two another tables in sqlalchemy?

From:
Mauricio de Abreu Antunes
Date:
2013-07-12 @ 14:24
Cliff, I don't think he is going to save that information on blobs
types. He does not even have blobs. :)

2013/7/12 Cliff Kachinske <cjkske@gmail.com>:
> My suggestion is to rethink your design.
>
> If the two blobs are truly the same, it's just a waste of disk space.
>
> Honestly I don't really understand why you need separate tables for songs
> and videos.  Blobs are just blobs, after all.  If you need to distinguish
> between them, just add a column for media_type and take it from there.
>
>
> On Fri, Jul 12, 2013 at 8:30 AM, Kundan Singh <ksingh.pilani@gmail.com>
> wrote:
>>
>> I am writing a flask+python application in which i have used
>> **SqlAlchemy** for database. I have two tables **songs** and **videos** in
>> which data is stored, its models are:
>>
>>     class song(db.Model):
>>         __tablename__ = 'song'
>>         id = db.Column(db.Integer, primary_key=True)
>>         songtitle = db.Column(db.Text, nullable=False)
>>         songurl= db.Column(db.Text, nullable=False)
>>         songlyrics= db.Column(db.Text, nullable=False)
>>         songdate =db.Column(db.Date,nullable = False)
>>
>>        def__init__(#parameters):
>>           #parameter values
>>
>>
>>     class video(db.Model):
>>         __tablename__ = 'video'
>>         id = db.Column(db.Integer, primary_key=True)
>>         videotitle = db.Column(db.Text, nullable=False)
>>         videourl= db.Column(db.Text, nullable=False)
>>         videolyrics= db.Column(db.Text, nullable=False)
>>         videodate =db.Column(db.Date,nullable = False)
>>
>>         def__init__(#parameters):
>>           #parameter values
>>
>> And i have another table named **mediafeed** as:
>>
>>
>>
>>       class mediafeed(db.Model):
>>             __tablename__ = 'mediafeed'
>>             id = db.Column(db.Integer, primary_key=True)
>>             mediafeedtitle = db.Column(db.Text, nullable=False)
>>             mediafeedurl= db.Column(db.Text, nullable=False)
>>             mediafeedlyrics= db.Column(db.Text, nullable=False)
>>             mediafeeddate =db.Column(db.Date,nullable = False)
>>
>>             def__init__(#parameters):
>>               #parameter values
>>
>> Data into **songs** and **videos** tables are added by Users of
>> application but i need the data stored into **mediafeed** table to be used
>> for other operations.
>>
>> the data should be sorted by columns **songdate** and **videodate** and
>> then it should be entered into the **mediafield** table accordingly on
>> running a script.
>>
>> suppose: video table data is:
>>   '1' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
>> '2013-7-10'
>>   '2' 'gangam style' 'www.video.us/gangam-style' 'oopm gangam style'
>> '2013-7-4'
>>
>> suppose: song table data is:
>>   '1' 'loving you' 'www.song.us/love-you' 'love you forever' '2013-7-5'
>>   '2' 'let's party' 'www.song.us/let's party' 'let's party tonight'
>> '2013-7-3'
>>
>> so i want the data into mediafeed table as:
>>   '1' 'song: let's party' 'www.song.us/let's party' 'let's party tonight'
>> '2013-7-3'
>>   '2' 'video: gangam style' 'www.video.us/gangam-style' 'oopm gangam
>> style' '2013-7-4'
>>   '3' 'song: loving you' 'www.song.us/love-you' 'love you forever'
>> '2013-7-5'
>>   '4' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
>> '2013-7-10'
>>
>> My purpose is to write a python method using sqlalchemy functions, so that
>> i can run it and data into mediafeed would be added from other tables as
>> required.
>>
>> Please help or suggest. Or provide any specific tutorial link etc.
>>
>> Thanks
>> Kundan Singh
>
>



-- 
Mauricio de Abreu Antunes
Mobile: (51)930-74-525
Skype: mauricio.abreua

Re: [flask] how to insert data into main table from two another tables in sqlalchemy?

From:
Kundan Singh
Date:
2013-07-12 @ 15:28
Okay guys...

I understand you suggestions... But two blobs are entirely different and
what i have shown you as models of tables are nor the real one. I created
dummy models just to serve the purpose. (I can't share actual models openly)

My issue is *how do you insert data into a main table after fetching data
from two different tables (almost similar) and sorting them according to a
datetime type column?* I need a suggestion regarding how to write such
script for sqlalchemy? as i din't find any good resources out there
regarding this. I just need a small basic script, rest logic i can develop
myself.

Regards


On Fri, Jul 12, 2013 at 7:54 PM, Mauricio de Abreu Antunes <
mauricio.abreua@gmail.com> wrote:

> Cliff, I don't think he is going to save that information on blobs
> types. He does not even have blobs. :)
>
> 2013/7/12 Cliff Kachinske <cjkske@gmail.com>:
> > My suggestion is to rethink your design.
> >
> > If the two blobs are truly the same, it's just a waste of disk space.
> >
> > Honestly I don't really understand why you need separate tables for songs
> > and videos.  Blobs are just blobs, after all.  If you need to distinguish
> > between them, just add a column for media_type and take it from there.
> >
> >
> > On Fri, Jul 12, 2013 at 8:30 AM, Kundan Singh <ksingh.pilani@gmail.com>
> > wrote:
> >>
> >> I am writing a flask+python application in which i have used
> >> **SqlAlchemy** for database. I have two tables **songs** and **videos**
> in
> >> which data is stored, its models are:
> >>
> >>     class song(db.Model):
> >>         __tablename__ = 'song'
> >>         id = db.Column(db.Integer, primary_key=True)
> >>         songtitle = db.Column(db.Text, nullable=False)
> >>         songurl= db.Column(db.Text, nullable=False)
> >>         songlyrics= db.Column(db.Text, nullable=False)
> >>         songdate =db.Column(db.Date,nullable = False)
> >>
> >>        def__init__(#parameters):
> >>           #parameter values
> >>
> >>
> >>     class video(db.Model):
> >>         __tablename__ = 'video'
> >>         id = db.Column(db.Integer, primary_key=True)
> >>         videotitle = db.Column(db.Text, nullable=False)
> >>         videourl= db.Column(db.Text, nullable=False)
> >>         videolyrics= db.Column(db.Text, nullable=False)
> >>         videodate =db.Column(db.Date,nullable = False)
> >>
> >>         def__init__(#parameters):
> >>           #parameter values
> >>
> >> And i have another table named **mediafeed** as:
> >>
> >>
> >>
> >>       class mediafeed(db.Model):
> >>             __tablename__ = 'mediafeed'
> >>             id = db.Column(db.Integer, primary_key=True)
> >>             mediafeedtitle = db.Column(db.Text, nullable=False)
> >>             mediafeedurl= db.Column(db.Text, nullable=False)
> >>             mediafeedlyrics= db.Column(db.Text, nullable=False)
> >>             mediafeeddate =db.Column(db.Date,nullable = False)
> >>
> >>             def__init__(#parameters):
> >>               #parameter values
> >>
> >> Data into **songs** and **videos** tables are added by Users of
> >> application but i need the data stored into **mediafeed** table to be
> used
> >> for other operations.
> >>
> >> the data should be sorted by columns **songdate** and **videodate** and
> >> then it should be entered into the **mediafield** table accordingly on
> >> running a script.
> >>
> >> suppose: video table data is:
> >>   '1' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
> >> '2013-7-10'
> >>   '2' 'gangam style' 'www.video.us/gangam-style' 'oopm gangam style'
> >> '2013-7-4'
> >>
> >> suppose: song table data is:
> >>   '1' 'loving you' 'www.song.us/love-you' 'love you forever' '2013-7-5'
> >>   '2' 'let's party' 'www.song.us/let's party' 'let's party tonight'
> >> '2013-7-3'
> >>
> >> so i want the data into mediafeed table as:
> >>   '1' 'song: let's party' 'www.song.us/let's party' 'let's party
> tonight'
> >> '2013-7-3'
> >>   '2' 'video: gangam style' 'www.video.us/gangam-style' 'oopm gangam
> >> style' '2013-7-4'
> >>   '3' 'song: loving you' 'www.song.us/love-you' 'love you forever'
> >> '2013-7-5'
> >>   '4' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
> >> '2013-7-10'
> >>
> >> My purpose is to write a python method using sqlalchemy functions, so
> that
> >> i can run it and data into mediafeed would be added from other tables as
> >> required.
> >>
> >> Please help or suggest. Or provide any specific tutorial link etc.
> >>
> >> Thanks
> >> Kundan Singh
> >
> >
>
>
>
> --
> Mauricio de Abreu Antunes
> Mobile: (51)930-74-525
> Skype: mauricio.abreua
>

Re: [flask] how to insert data into main table from two another tables in sqlalchemy?

From:
Eamon Banta
Date:
2013-07-12 @ 15:47
You could use Insert.from_select:


http://docs.sqlalchemy.org/en/rel_0_8/core/expression_api.html#sqlalchemy.sql.expression.Insert.from_select

sel = select([table1.c.a, table1.c.b]).where(table1.c.c > 5)ins =
table2.insert().from_select(['a', 'b'], sel)

Your select would have to use a join (that could then be ordered by
date) to produce your unified data set to insert into the third table.




On Fri, Jul 12, 2013 at 11:28 AM, Kundan Singh <ksingh.pilani@gmail.com>wrote:

> Okay guys...
>
> I understand you suggestions... But two blobs are entirely different and
> what i have shown you as models of tables are nor the real one. I created
> dummy models just to serve the purpose. (I can't share actual models openly)
>
> My issue is *how do you insert data into a main table after fetching data
> from two different tables (almost similar) and sorting them according to a
> datetime type column?* I need a suggestion regarding how to write such
> script for sqlalchemy? as i din't find any good resources out there
> regarding this. I just need a small basic script, rest logic i can develop
> myself.
>
> Regards
>
>
> On Fri, Jul 12, 2013 at 7:54 PM, Mauricio de Abreu Antunes <
> mauricio.abreua@gmail.com> wrote:
>
>> Cliff, I don't think he is going to save that information on blobs
>> types. He does not even have blobs. :)
>>
>> 2013/7/12 Cliff Kachinske <cjkske@gmail.com>:
>> > My suggestion is to rethink your design.
>> >
>> > If the two blobs are truly the same, it's just a waste of disk space.
>> >
>> > Honestly I don't really understand why you need separate tables for
>> songs
>> > and videos.  Blobs are just blobs, after all.  If you need to
>> distinguish
>> > between them, just add a column for media_type and take it from there.
>> >
>> >
>> > On Fri, Jul 12, 2013 at 8:30 AM, Kundan Singh <ksingh.pilani@gmail.com>
>> > wrote:
>> >>
>> >> I am writing a flask+python application in which i have used
>> >> **SqlAlchemy** for database. I have two tables **songs** and
>> **videos** in
>> >> which data is stored, its models are:
>> >>
>> >>     class song(db.Model):
>> >>         __tablename__ = 'song'
>> >>         id = db.Column(db.Integer, primary_key=True)
>> >>         songtitle = db.Column(db.Text, nullable=False)
>> >>         songurl= db.Column(db.Text, nullable=False)
>> >>         songlyrics= db.Column(db.Text, nullable=False)
>> >>         songdate =db.Column(db.Date,nullable = False)
>> >>
>> >>        def__init__(#parameters):
>> >>           #parameter values
>> >>
>> >>
>> >>     class video(db.Model):
>> >>         __tablename__ = 'video'
>> >>         id = db.Column(db.Integer, primary_key=True)
>> >>         videotitle = db.Column(db.Text, nullable=False)
>> >>         videourl= db.Column(db.Text, nullable=False)
>> >>         videolyrics= db.Column(db.Text, nullable=False)
>> >>         videodate =db.Column(db.Date,nullable = False)
>> >>
>> >>         def__init__(#parameters):
>> >>           #parameter values
>> >>
>> >> And i have another table named **mediafeed** as:
>> >>
>> >>
>> >>
>> >>       class mediafeed(db.Model):
>> >>             __tablename__ = 'mediafeed'
>> >>             id = db.Column(db.Integer, primary_key=True)
>> >>             mediafeedtitle = db.Column(db.Text, nullable=False)
>> >>             mediafeedurl= db.Column(db.Text, nullable=False)
>> >>             mediafeedlyrics= db.Column(db.Text, nullable=False)
>> >>             mediafeeddate =db.Column(db.Date,nullable = False)
>> >>
>> >>             def__init__(#parameters):
>> >>               #parameter values
>> >>
>> >> Data into **songs** and **videos** tables are added by Users of
>> >> application but i need the data stored into **mediafeed** table to be
>> used
>> >> for other operations.
>> >>
>> >> the data should be sorted by columns **songdate** and **videodate** and
>> >> then it should be entered into the **mediafield** table accordingly on
>> >> running a script.
>> >>
>> >> suppose: video table data is:
>> >>   '1' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
>> >> '2013-7-10'
>> >>   '2' 'gangam style' 'www.video.us/gangam-style' 'oopm gangam style'
>> >> '2013-7-4'
>> >>
>> >> suppose: song table data is:
>> >>   '1' 'loving you' 'www.song.us/love-you' 'love you forever'
>> '2013-7-5'
>> >>   '2' 'let's party' 'www.song.us/let's party' 'let's party tonight'
>> >> '2013-7-3'
>> >>
>> >> so i want the data into mediafeed table as:
>> >>   '1' 'song: let's party' 'www.song.us/let's party' 'let's party
>> tonight'
>> >> '2013-7-3'
>> >>   '2' 'video: gangam style' 'www.video.us/gangam-style' 'oopm gangam
>> >> style' '2013-7-4'
>> >>   '3' 'song: loving you' 'www.song.us/love-you' 'love you forever'
>> >> '2013-7-5'
>> >>   '4' 'flying birds' 'www.video.us/flying-bird' 'flying high birds'
>> >> '2013-7-10'
>> >>
>> >> My purpose is to write a python method using sqlalchemy functions, so
>> that
>> >> i can run it and data into mediafeed would be added from other tables
>> as
>> >> required.
>> >>
>> >> Please help or suggest. Or provide any specific tutorial link etc.
>> >>
>> >> Thanks
>> >> Kundan Singh
>> >
>> >
>>
>>
>>
>> --
>> Mauricio de Abreu Antunes
>> Mobile: (51)930-74-525
>> Skype: mauricio.abreua
>>
>
>

Re: [flask] how to insert data into main table from two another tables in sqlalchemy?

From:
paalzza
Date:
2013-07-13 @ 13:22
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
<a class="moz-txt-link-freetext" 
href="http://stackoverflow.com/questions/1849375/how-do-i-insert-into-t1-select-from-t2-in-sqlalchemy">http://stackoverflow.com/questions/1849375/how-do-i-insert-into-t1-select-from-t2-in-sqlalchemy</a><br>
    <br>
    <div class="moz-cite-prefix">12.07.2013 19:47, Eamon Banta пишет:<br>
    </div>
    <blockquote
cite="mid:CAJ6gNcRj9A5iwZmU=AueuPN_b0=JRg3g8XTbRS_BhpTwFEgyYw@mail.gmail.com"
      type="cite">
      <div dir="ltr">You could use Insert.from_select:<br>
        <br>
        <a moz-do-not-send="true"

href="http://docs.sqlalchemy.org/en/rel_0_8/core/expression_api.html#sqlalchemy.sql.expression.Insert.from_select">http://docs.sqlalchemy.org/en/rel_0_8/core/expression_api.html#sqlalchemy.sql.expression.Insert.from_select</a><br>
        <div class="">
          <div class="">
            <pre><span class="">sel</span> <span class="">=</span> <span 
class="">select</span><span class="">([</span><span 
class="">table1</span><span class="">.</span><span class="">c</span><span 
class="">.</span><span class="">a</span><span class="">,</span> <span 
class="">table1</span><span class="">.</span><span class="">c</span><span 
class="">.</span><span class="">b</span><span class="">])</span><span 
class="">.</span><span class="">where</span><span class="">(</span><span 
class="">table1</span><span class="">.</span><span class="">c</span><span 
class="">.</span><span class="">c</span> <span class="">></span> <span 
class="">5</span><span class="">)</span>
<span class="">ins</span> <span class="">=</span> <span 
class="">table2</span><span class="">.</span><span 
class="">insert</span><span class="">()</span><span class="">.</span><span
class="">from_select</span><span class="">([</span><span 
class="">'a'</span><span class="">,</span> <span class="">'b'</span><span 
class="">],</span> <span class="">sel</span><span class="">)


</span></pre>
            <pre><span class="">Your select would have to use a join (that
could then be ordered by date) to produce your unified data set to insert 
into the third table.
</span></pre>
          </div>
        </div>
        <br>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Fri, Jul 12, 2013 at 11:28 AM,
          Kundan Singh <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:ksingh.pilani@gmail.com" 
target="_blank">ksingh.pilani@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">Okay guys...
              <div><br>
              </div>
              <div>I understand you suggestions... But two blobs are
                entirely different and what i have shown you as models
                of tables are nor the real one. I created dummy models
                just to serve the purpose. (I can't share actual models
                openly)</div>
              <div><br>
              </div>
              <div>My issue is <b>how do you insert data into a main
                  table after fetching data from two different tables
                  (almost similar) and sorting them according to a
                  datetime type column?</b> I need a suggestion
                regarding how to write such script for sqlalchemy? as i
                din't find any good resources out there regarding this.
                I just need a small basic script, rest logic i can
                develop myself.</div>
              <div><br>
              </div>
              <div>Regards</div>
            </div>
            <div class="gmail_extra"><br>
              <br>
              <div class="gmail_quote">On Fri, Jul 12, 2013 at 7:54 PM,
                Mauricio de Abreu Antunes <span dir="ltr"><<a
                    moz-do-not-send="true"
                    href="mailto:mauricio.abreua@gmail.com"
                    target="_blank">mauricio.abreua@gmail.com</a>></span>
                wrote:<br>
                <blockquote class="gmail_quote" style="margin:0 0 0
                  .8ex;border-left:1px #ccc solid;padding-left:1ex">Cliff,
                  I don't think he is going to save that information on
                  blobs<br>
                  types. He does not even have blobs. :)<br>
                  <br>
                  2013/7/12 Cliff Kachinske <<a
                    moz-do-not-send="true"
                    href="mailto:cjkske@gmail.com" 
target="_blank">cjkske@gmail.com</a>>:<br>
                  <div>
                    <div>> My suggestion is to rethink your design.<br>
                      ><br>
                      > If the two blobs are truly the same, it's
                      just a waste of disk space.<br>
                      ><br>
                      > Honestly I don't really understand why you
                      need separate tables for songs<br>
                      > and videos.  Blobs are just blobs, after all.
                       If you need to distinguish<br>
                      > between them, just add a column for
                      media_type and take it from there.<br>
                      ><br>
                      ><br>
                      > On Fri, Jul 12, 2013 at 8:30 AM, Kundan Singh
                      <<a moz-do-not-send="true"
                        href="mailto:ksingh.pilani@gmail.com"
                        target="_blank">ksingh.pilani@gmail.com</a>><br>
                      > wrote:<br>
                      >><br>
                      >> I am writing a flask+python application
                      in which i have used<br>
                      >> **SqlAlchemy** for database. I have two
                      tables **songs** and **videos** in<br>
                      >> which data is stored, its models are:<br>
                      >><br>
                      >>     class song(db.Model):<br>
                      >>         __tablename__ = 'song'<br>
                      >>         id = db.Column(db.Integer,
                      primary_key=True)<br>
                      >>         songtitle = db.Column(db.Text,
                      nullable=False)<br>
                      >>         songurl= db.Column(db.Text,
                      nullable=False)<br>
                      >>         songlyrics= db.Column(db.Text,
                      nullable=False)<br>
                      >>         songdate
                      =db.Column(db.Date,nullable = False)<br>
                      >><br>
                      >>        def__init__(#parameters):<br>
                      >>           #parameter values<br>
                      >><br>
                      >><br>
                      >>     class video(db.Model):<br>
                      >>         __tablename__ = 'video'<br>
                      >>         id = db.Column(db.Integer,
                      primary_key=True)<br>
                      >>         videotitle = db.Column(db.Text,
                      nullable=False)<br>
                      >>         videourl= db.Column(db.Text,
                      nullable=False)<br>
                      >>         videolyrics= db.Column(db.Text,
                      nullable=False)<br>
                      >>         videodate
                      =db.Column(db.Date,nullable = False)<br>
                      >><br>
                      >>         def__init__(#parameters):<br>
                      >>           #parameter values<br>
                      >><br>
                      >> And i have another table named
                      **mediafeed** as:<br>
                      >><br>
                      >><br>
                      >><br>
                      >>       class mediafeed(db.Model):<br>
                      >>             __tablename__ = 'mediafeed'<br>
                      >>             id = db.Column(db.Integer,
                      primary_key=True)<br>
                      >>             mediafeedtitle =
                      db.Column(db.Text, nullable=False)<br>
                      >>             mediafeedurl=
                      db.Column(db.Text, nullable=False)<br>
                      >>             mediafeedlyrics=
                      db.Column(db.Text, nullable=False)<br>
                      >>             mediafeeddate
                      =db.Column(db.Date,nullable = False)<br>
                      >><br>
                      >>             def__init__(#parameters):<br>
                      >>               #parameter values<br>
                      >><br>
                      >> Data into **songs** and **videos** tables
                      are added by Users of<br>
                      >> application but i need the data stored
                      into **mediafeed** table to be used<br>
                      >> for other operations.<br>
                      >><br>
                      >> the data should be sorted by columns
                      **songdate** and **videodate** and<br>
                      >> then it should be entered into the
                      **mediafield** table accordingly on<br>
                      >> running a script.<br>
                      >><br>
                      >> suppose: video table data is:<br>
                      >>   '1' 'flying birds' '<a
                        moz-do-not-send="true"
                        href="http://www.video.us/flying-bird"
                        target="_blank">www.video.us/flying-bird</a>'
                      'flying high birds'<br>
                      >> '2013-7-10'<br>
                      >>   '2' 'gangam style' '<a
                        moz-do-not-send="true"
                        href="http://www.video.us/gangam-style"
                        target="_blank">www.video.us/gangam-style</a>'
                      'oopm gangam style'<br>
                      >> '2013-7-4'<br>
                      >><br>
                      >> suppose: song table data is:<br>
                      >>   '1' 'loving you' '<a
                        moz-do-not-send="true"
                        href="http://www.song.us/love-you"
                        target="_blank">www.song.us/love-you</a>' 'love
                      you forever' '2013-7-5'<br>
                      >>   '2' 'let's party' '<a
                        moz-do-not-send="true"
                        href="http://www.song.us/let%27s"
                        target="_blank">www.song.us/let's</a> party'
                      'let's party tonight'<br>
                      >> '2013-7-3'<br>
                      >><br>
                      >> so i want the data into mediafeed table
                      as:<br>
                      >>   '1' 'song: let's party' '<a
                        moz-do-not-send="true"
                        href="http://www.song.us/let%27s"
                        target="_blank">www.song.us/let's</a> party'
                      'let's party tonight'<br>
                      >> '2013-7-3'<br>
                      >>   '2' 'video: gangam style' '<a
                        moz-do-not-send="true"
                        href="http://www.video.us/gangam-style"
                        target="_blank">www.video.us/gangam-style</a>'
                      'oopm gangam<br>
                      >> style' '2013-7-4'<br>
                      >>   '3' 'song: loving you' '<a
                        moz-do-not-send="true"
                        href="http://www.song.us/love-you"
                        target="_blank">www.song.us/love-you</a>' 'love
                      you forever'<br>
                      >> '2013-7-5'<br>
                      >>   '4' 'flying birds' '<a
                        moz-do-not-send="true"
                        href="http://www.video.us/flying-bird"
                        target="_blank">www.video.us/flying-bird</a>'
                      'flying high birds'<br>
                      >> '2013-7-10'<br>
                      >><br>
                      >> My purpose is to write a python method
                      using sqlalchemy functions, so that<br>
                      >> i can run it and data into mediafeed
                      would be added from other tables as<br>
                      >> required.<br>
                      >><br>
                      >> Please help or suggest. Or provide any
                      specific tutorial link etc.<br>
                      >><br>
                      >> Thanks<br>
                      >> Kundan Singh<br>
                      ><br>
                      ><br>
                      <br>
                      <br>
                      <span class="HOEnZb"><font color="#888888">
                          <br>
                        </font></span></div>
                  </div>
                  <span class="HOEnZb"><font color="#888888"><span><font
                          color="#888888">--<br>
                          Mauricio de Abreu Antunes<br>
                          Mobile: <a moz-do-not-send="true"
                            href="tel:%2851%29930-74-525"
                            value="+15193074525" 
target="_blank">(51)930-74-525</a><br>
                          Skype: mauricio.abreua<br>
                        </font></span></font></span></blockquote>
              </div>
              <br>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>