1

I am using PostgreSQL Database. create a search query in using codeigniter like function.

$this->db->($colName."::text", $value)->get("datatables_demo");

SELECT * FROM "datatables_demo" WHERE  "first_name::text" like '%co%'

But in PostgreSQL shows error, I want output like that

 SELECT * FROM "datatables_demo" WHERE  first_name::text like '%co%'

Is there any option in codeigniter to remove inverted comma from like function ihave tried to send false in 3rd argument false

$this->db->($colName."::text", $value, false)

Give any option to resolve this issue using like function

Query:SELECT * FROM "datatables_demo" WHERE "salary::text" LIKE '%320%' ESCAPE '!'

When i run this query in postgresql 
ERROR:  column "salary::text" does not exist
LINE 1: SELECT * FROM "datatables_demo" WHERE  "salary::text"  LIKE ...
                                               ^
********** Error **********

ERROR: column "salary::text" does not exist
SQL state: 42703
Character: 40

But when i remove inverted comma from column it return result succuessfully

SELECT * FROM "datatables_demo" WHERE salary::text LIKE '%320%' ESCAPE '!'

Ajeet Kumar
  • 805
  • 1
  • 7
  • 26

2 Answers2

3

If you thinking of sql like function try this.

$sql = ('SELECT * FROM datatables_demo WHERE salary::text LIKE ?');
$query = $this->db->query($sql, array($value . '%'));
jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65
  • I have more than 10 columns to add like and column name will be dynamic in this case and columns can be vary with order by and limit so that i am avoiding to use static query . – Ajeet Kumar Mar 02 '16 at 13:37
0

I think in codeigniter2 PostgreSql driver has like operator previous versions codes. If you want to in use codeigniter like function to build query you have to make some change in codeigniter system database library I am give you changes in this path

system\database\drivers\postgre\postgre_driver.php

In line no 36

var $_escape_char = '"';

Replace with

var $_escape_char = '';

Your query output same as you expected o/p BEST OF LUCK