Forum: Ruby on Rails simplify

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.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-26 07:30
(Received via mailing list)
Trying to use Eric's help and Amy Hoy's page of playing with
auto_complete and decided that the script/console is the place to
rapidly test.

I have this feeling that CONCAT isn't working for postgresql...

c = find_by_sql(SELECT * FROM clients WHERE CONCAT
(first_name,middle_initial,last_name) = "johnadams")
                                     ^
(irb):61: syntax error
c = find_by_sql(SELECT * FROM clients WHERE CONCAT
(first_name,middle_initial,last_name) = "johnadams")

^
        from (irb):61

As you can tell...I've taken a number of stabs at it and simplified it
down as much as I can.

postgresql-7.4.8-1.RHEL-4.1

I can do single field searches and multi-field searches and the
concatenated searches clearly is what I need.

Craig
Ac1da5d66d51a1c3b843221032247b30?d=identicon&s=25 Eric Goodwin (Guest)
on 2006-02-26 07:42
(Received via mailing list)
Hi Craig,
CONCAT is actually a mysql function. Sorry about that. For Postgres I
believe you use a || to concatenate.

ex.
SELECT * FROM users WHERE firstname||lastname = 'EricGoodwin'

Cheers,
Eric Goodwin
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 joey__ (Guest)
on 2006-02-26 11:25
Craig White wrote:
> Trying to use Eric's help and Amy Hoy's page of playing with
> auto_complete and decided that the script/console is the place to
> rapidly test.
>
> I have this feeling that CONCAT isn't working for postgresql...
>
> c = find_by_sql(SELECT * FROM clients WHERE CONCAT
> (first_name,middle_initial,last_name) = "johnadams")
>                                      ^
> (irb):61: syntax error
> c = find_by_sql(SELECT * FROM clients WHERE CONCAT
> (first_name,middle_initial,last_name) = "johnadams")
>
> ^
>         from (irb):61
>
> As you can tell...I've taken a number of stabs at it and simplified it
> down as much as I can.
>
> postgresql-7.4.8-1.RHEL-4.1
>
> I can do single field searches and multi-field searches and the
> concatenated searches clearly is what I need.
>
> Craig

The syntax is wrong, you missed off quotes.
c = find_by_sql("SELECT * FROM clients WHERE
CONCAT(first_name,middle_initial,last_name) = 'johnadams'")

See if that works.

Joey__
http://www.feedreed.com
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-26 17:14
(Received via mailing list)
On Sun, 2006-02-26 at 11:25 +0100, joey__ wrote:
> > (irb):61: syntax error
> >
> > I can do single field searches and multi-field searches and the
> > concatenated searches clearly is what I need.
> >
> > Craig
>
> The syntax is wrong, you missed off quotes.
> c = find_by_sql("SELECT * FROM clients WHERE
> CONCAT(first_name,middle_initial,last_name) = 'johnadams'")
>
> See if that works.
----
perhaps for mysql but CONCAT isn't syntactically correct for postgresql
as Eric pointed out - which also explains why I couldn't find any
references for it in my PostgreSQL book too. The || operator worked fine
for PostgreSQL and my only issue remaining is returning the found items
back into the calling code...not a simple matter.

Thanks

Craig
This topic is locked and can not be replied to.