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.
2da46bf3608ac6f8b50db545e267ce5c?d=identicon&s=25 Ukrit Himakoon (ukarick)
on 2009-02-03 08: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?
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-02-03 08: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.
2da46bf3608ac6f8b50db545e267ce5c?d=identicon&s=25 Ukrit Himakoon (ukarick)
on 2009-02-03 10: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? :)
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-02-03 11:56
(Received via mailing list)
You could have another column in the table, containing the short
version.

2009/2/3 Ukrit Himakoon <rails-mailing-list@andreas-s.net>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-03 12: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
2da46bf3608ac6f8b50db545e267ce5c?d=identicon&s=25 Ukrit Himakoon (ukarick)
on 2009-02-04 08:37
Frederick Cheung 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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-04 10:28
(Received via mailing list)
On Feb 4, 7:37 am, Ukrit Himakoon <rails-mailing-l...@andreas-s.net>
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.