Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Processing postgres table

Reply
Thread Tools

Processing postgres table

 
 
Dan Webb
Guest
Posts: n/a
 
      10-22-2008
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/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      10-23-2008
2008/10/22 Dan Webb <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Postgres/Postgres-pr - some confusion Nick Black Ruby 1 11-16-2006 08:01 PM
Post-Processing RAW vs Post-Processing TIFF Mike Henley Digital Photography 42 01-30-2005 08:26 AM
Table/table rows/table data tag question? Rio HTML 4 11-05-2004 08:11 AM
Question: processing HTML, re-write default processing action of many tags Hubert Hung-Hsien Chang Python 2 09-17-2004 03:10 PM
Could not load type VTFixup Table from assembly Invalid token in v-table fix-up table. David Williams ASP .Net 2 08-12-2003 07:55 AM



Advertisments