Processing postgres table

Discussion in 'Ruby' started by Dan Webb, Oct 22, 2008.

  1. Dan Webb

    Dan Webb Guest

    I'm using the ruby-postgres gem as ruby-pg isn't installing & as there
    no longer seems to be any tutorials or how-tos I thought I'd ask here.

    Basically I'm trying to iterate through each row of data and assign the
    values to some variables then print them out to XML (XML output's sorted
    thanks to builder)
    This is one set of that data, one question with 5 answers. How can I go
    about finding out the number of rows that contain the same first column?


    "A new question by mbr - option 3 is the correct
    option";"afsdfsd";"mbr";"";FALSE;"-0.25";"1";"''"

    "A new question by mbr - option 3 is the correct
    option";"sdfsdf";"mbr";"";FALSE;"-0.25";"2";"''"

    "A new question by mbr - option 3 is the correct
    option";"sdfsdf";"mbr";"";TRUE;"1.0";"3";"''"

    "A new question by mbr - option 3 is the correct
    option";"sdfsdf";"mbr";"";FALSE;"-0.25";"4";"''"

    "A new question by mbr - option 3 is the correct
    option";"sdfsdaf";"mbr";"";FALSE;"-0.25";"5";"''"



    This is the current code I'm using for postgres.
    db = PGconn.connect(pghost, pgport,'','',pgtbl,dbname,'')
    results = db.exec('SELECT question_stem, option_text, author_id,
    module_code, correct, weighting, option_id, feedback FROM RESULTS_JOIN')
    results.each do |row|
    puts "by position: #{row[0]} #{row[1]} #{row[2]} #{row[3]} #{row[4]}
    #{row[5]} #{row[6]} #{row[7]} "
    end

    any pointers would be great.
    Kind Regards,
    Dan
    --
    Posted via http://www.ruby-forum.com/.
    Dan Webb, Oct 22, 2008
    #1
    1. Advertising

  2. 2008/10/22 Dan Webb <>:
    > I'm using the ruby-postgres gem as ruby-pg isn't installing & as there
    > no longer seems to be any tutorials or how-tos I thought I'd ask here.
    >
    > Basically I'm trying to iterate through each row of data and assign the
    > values to some variables then print them out to XML (XML output's sorted
    > thanks to builder)
    > This is one set of that data, one question with 5 answers. How can I go
    > about finding out the number of rows that contain the same first column?


    SELECT question_stem, count(*)
    FROM RESULTS_JOIN
    group by question_stem

    Cheers

    robert

    --
    remember.guy do |as, often| as.you_can - without end
    Robert Klemme, Oct 23, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam
    Replies:
    2
    Views:
    1,575
    Wm. G. Urquhart
    Jul 10, 2003
  2. David Williams
    Replies:
    2
    Views:
    1,107
    Jacob Yang [MSFT]
    Aug 12, 2003
  3. Rio
    Replies:
    4
    Views:
    1,174
  4. Hubert Hung-Hsien Chang
    Replies:
    2
    Views:
    410
    Michael Foord
    Sep 17, 2004
  5. Nick Black
    Replies:
    1
    Views:
    146
    Kashia Buch
    Nov 16, 2006
Loading...

Share This Page