Forum: Ruby on Rails Query some part on each record.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ukrit H. (Guest)
on 2009-02-03 09:38
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?
MaD (Guest)
on 2009-02-03 09:49
(Received via mailing list)
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.
Ukrit H. (Guest)
on 2009-02-03 11:16
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 :D
Any other solution? :)
Colin L. (Guest)
on 2009-02-03 12:56
(Received via mailing list)
You could have another column in the table, containing the short
version.

2009/2/3 Ukrit H. <removed_email_address@domain.invalid>
Frederick C. (Guest)
on 2009-02-03 13:00
(Received via mailing list)
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
Ukrit H. (Guest)
on 2009-02-04 09:37
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.
Frederick C. (Guest)
on 2009-02-04 11:28
(Received via mailing list)
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
This topic is locked and can not be replied to.