Ranges and List Comprehensions in SQL

Hi Everyone, Is there a "From SQL"-type function that "restores" a range or list comprehension? Example: Let's say I want to keep track of which episodes of a TV show I've seen. I have an SQL table, in which is a record: id (INTEGER): 30 title (VARCHAR): "The Simpsons" episodes_watched (Some data format): [1..4], [14], [18..21], [23..25] Then, when I pull the record, in Haskell, the "Episodes Watched" is already one list: [1,2,3,4,14,18,19,21,23,24,25] , or a series of lists that I can append together: [1,2,3,4], [14], [18,19,20,21], [23,24,25] Note in the example that I would like to be able to store multiple ranges within a single record. Thanks so much for any help! Tom

On Thu, Sep 02, 2010 at 03:54:12PM -0400, Tom Murphy wrote:
Hi Everyone,
Is there a "From SQL"-type function that "restores" a range or list comprehension?
Example: Let's say I want to keep track of which episodes of a TV show I've seen. I have an SQL table, in which is a record: id (INTEGER): 30 title (VARCHAR): "The Simpsons" episodes_watched (Some data format): [1..4], [14], [18..21], [23..25]
Then, when I pull the record, in Haskell, the "Episodes Watched" is already one list: [1,2,3,4,14,18,19,21,23,24,25]
, or a series of lists that I can append together: [1,2,3,4], [14], [18,19,20,21], [23,24,25]
Note in the example that I would like to be able to store multiple ranges within a single record.
I am not sure I understand what you are asking. Do you want something like this? data Range = Range Integer Integer toRanges :: [Integer] -> [Range] toRanges = ... toRanges should not be too hard to write but nothing like that exists as far as I know. But I'm pretty sure I haven't understood your question, because I don't see what SQL has to do with it. Are you actually using a database? Or are you just using SQL as inspiration? -Brent

On 2-Sep-10, at 3:54 PM, Tom Murphy wrote:
Hi Everyone,
Is there a "From SQL"-type function that "restores" a range or list comprehension?
Example: Let's say I want to keep track of which episodes of a TV show I've seen. I have an SQL table, in which is a record: id (INTEGER): 30 title (VARCHAR): "The Simpsons" episodes_watched (Some data format): [1..4], [14], [18..21], [23..25]
To model this relationally, episodes_watched cannot be some kind of composite value. You need two relations, for example: CREATE TABLE tv_show ( id INTEGER NOT NULL, -- etc title VARCHAR(80), PRIMARY KEY (id) ); CREATE TABLE episodes_watched ( tv_show_id INTEGER NOT NULL, episode_number INTEGER, PRIMARY KEY (tv_show_id, episode_number) -- and ideally a foreign key constraint ); Data: tv_show (30, "The Simpsons") episodes_watched (30,1), (30,2), (30,3), (30,4), (30,14), (30,18), (30,19), (30,20), (30,21), (30,23), (30,24), (30,25) --Toby
Then, when I pull the record, in Haskell, the "Episodes Watched" is already one list: [1,2,3,4,14,18,19,21,23,24,25]
, or a series of lists that I can append together: [1,2,3,4], [14], [18,19,20,21], [23,24,25]
Note in the example that I would like to be able to store multiple ranges within a single record.
Thanks so much for any help! Tom _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (3)
-
Brent Yorgey
-
Toby Thain
-
Tom Murphy