Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Fetching data from DB and complex data structures

by chacham (Prior)
on Dec 14, 2015 at 16:32 UTC ( [id://1150245]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Fetching data from DB and complex data structures
in thread Fetching data from DB and complex data structures

If line_n and word_position (together) are not unique, how in the world do you build the string? Well, unless id breaks the ties.

If you want to see the work in progress, the recursive query is even easier. (No MAX in the anchor, and no WHERE clause is the main query.)

  • Comment on Re^3: Fetching data from DB and complex data structures

Replies are listed 'Best First'.
Re^4: Fetching data from DB and complex data structures
by frasco (Beadle) on Dec 14, 2015 at 16:55 UTC
    I'm not a software developer and maybe I miss something but the SQL solution I normally work with is:
    SELECT line_n,
    	GROUP_CONCAT(word ORDER BY id SEPARATOR ' ')
    	FROM myTable
    	WHERE myText = 'something'
    	GROUP BY line_n
    ORDER BY id
    
    In fact it is governed by the id

      GROUP_CONCAT is an RDBMS-specific function. Some others don't have it, some do, and then under other names.

      Anyway, the use of id is redundant and, for that matter, probably wrong, assuming i'm understanding the layout correctly.

      line_n groups all words in any given line together. word_position defines their order. id is the order in which they are inserted into the table. As it so happens, lines and words are inserted in order so id can be used as a surrogate for word_position to define the order. However, should a word be inserted out of order, a word_position be updated, or (a rare cases that applies only in some situations) the ids be reused, the usage of id may produce incorrect results. In any case, line_n and word_position will always be correct.

      The recursive query above should work. It has been modified to squelch the non-finished lines (via the MAX in the anchor). If the in-progress lines are desired, it is a simple modification.

      You haven't shown any myText column in the table sample.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1150245]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-20 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found