• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Typecast in Query Builder or Query

#1
Hello all, I'm having a problem when trying to typecast a value in my Postgres's DB wich is type TEXT to INT to perfom a Order By in a query.
When trying to use the standart QUERY() function I receive errors if I try using "ORDER BY option::int"


PHP Code:
$query_options $this->query("SELECT * FROM integrador_ura_options WHERE fk_ura_id = ? ORDER BY option::int"$fk_ura_id); 

<b>Fatal error</b>:  Uncaught CodeIgniter\Format\Exceptions\FormatException: Failed to parse json string, error: &quot;Type is not supported&quot;. in /var/www/html/integrador/system/Format/Exceptions/FormatException.php:9

And i didn't find any documentation about how to do it using QueryBuilder class.
Reply

#2
try SELECT x, y,z, ..., CAST(option AS INTEGER) AS option WHERE foo=? ORDER BY option, foo
Simpler is always better
Reply

#3
That worked, thanks.
But the problem is still there, I think in future releases of CI4 they must provide a way for doing this type of conversion.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.