B
B
BonBon Slick2017-02-01 10:53:26
PostgreSQL
BonBon Slick, 2017-02-01 10:53:26

Search ID like '11'?

I know how to do it on pure PG:
CAST (id as text ) LIKE '11'
In Laravel this does not work, I indicated in the class:

protected $casts = [
    'product_id' => 'string', // text ムひセミカミオ ミソムミセミアミセミイミーミサ
    ];
// ムひセミカミオ ミスミオ ムミーミアミセムひーミオム
DB::select('SELECT * FROM products  WHERE CAST(product_id AS TEXT)  LIKE 10');

Everywhere gives an error:
//ムひーミコムτ
FatalThrowableError in ProductController.php line 111:
Parse error: syntax error, unexpected as (T_AS), expecting ',' or ')'
in ProductController.php line 111
at Composer\Autoload\includeFile('C:\Users\BonBonS\Desktop\OpenServerUltimate\domains\market\vendor\composer/../../app/Http/Controllers/ProductController.php') in ClassLoader.php line 301........
// ミクミサミク 
QueryException in Connection.php line 770:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: integer ~~ unknown
LINE 1: select * from "products" where "product_id" LIKE $1 limit 1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. (SQL: select * from "products" where "product_id" LIKE %11% limit 1)
in Connection.php line 770
at Connection->runQueryCallback('select * from "products" where "product_id" LIKE ? limit 1', array('%11%'), object(Closure)) in Connection.php line 726
// ミ寅エミオ ムミーミシミーム ミウミサミーミイミスミーム ムミームムび ム采ひセ:
- operator does not exist: integer ~~ unknown 
- add explicit type casts

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shelemetiev, 2017-02-21
@BonBonSlick

The expression after LIKE must be in quotes. You can use $$ instead of single quotes

DB::select('SELECT * FROM products  WHERE CAST(product_id AS TEXT)  LIKE $$10$$');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question