Query some part on each record


#1

I would like to ask you this question
suppose that I’ve 1 record which contains very long contents like

Big_Row_Table

Row1|Big_Row|

Row1|very long contents

I would like to query only some part of Big row (such as get first 4
characters )of this row by running query commands like this:

GetsomePart = Big_Row_Table.find(somecommand)

GetsomePart.Big_Row

“very” <—this is the result I need

any idea?


#2

i don’t wann disappoint, but i think you’ll have to query the whole
entry “very long contents” and cut off the tail.

GetsomePart.Big_Row[0…3]

if anyone knows a better solution (one that offers more performance),
let me know.


#3

MaD wrote:

i don’t wann disappoint, but i think you’ll have to query the whole
entry “very long contents” and cut off the tail.

GetsomePart.Big_Row[0…3]

if anyone knows a better solution (one that offers more performance),
let me know.

Thx , Mad :smiley:
Any other solution? :slight_smile:


#4

On 3 Feb 2009, at 07:48, MaD wrote:

i don’t wann disappoint, but i think you’ll have to query the whole
entry “very long contents” and cut off the tail.

GetsomePart.Big_Row[0…3]

if anyone knows a better solution (one that offers more performance),
let me know.

Well I don’t know if it’s a good idea, probably database dependent
etc. etc. but Foo.find some_id, :select => ‘substring(bar,0, 5) as
bar, id, …’
Database almost certainly still needs to go and load that entire
column so I doubt it will make a huge difference.

Fred


#5

You could have another column in the table, containing the short
version.

2009/2/3 Ukrit H. removed_email_address@domain.invalid


#6

On Feb 4, 7:37 am, Ukrit H. removed_email_address@domain.invalid
wrote:

Would you please tell more details on this solution? Fred I’m not
clearly understand this.

There’s not a whole lot to it - use a select clause to control what is
fetched by the database.

Fred


#7

Frederick C. wrote:

On 3 Feb 2009, at 07:48, MaD wrote:

i don’t wann disappoint, but i think you’ll have to query the whole
entry “very long contents” and cut off the tail.

GetsomePart.Big_Row[0…3]

if anyone knows a better solution (one that offers more performance),
let me know.

Well I don’t know if it’s a good idea, probably database dependent
etc. etc. but Foo.find some_id, :select => ‘substring(bar,0, 5) as
bar, id, …’
Database almost certainly still needs to go and load that entire
column so I doubt it will make a huge difference.

Fred

Would you please tell more details on this solution? Fred I’m not
clearly understand this.