Query some part on each record

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?

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.

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:

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

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

2009/2/3 Ukrit H. [email protected]

On Feb 4, 7:37 am, Ukrit H. [email protected]
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

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.