İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
1543 Görünümler

following is  a table of product_attribute and i want to search record of attribute using name like 
self.env.cr.execute("SELECT id FROM product_attribute WHERE name='Legs'")

it raises a error 
psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type json

LINE 1: SELECT id FROM product_attribute WHERE name='Legs'



Any solution for this except using search() ? 

Avatar
Vazgeç
En İyi Yanıt

First off, if there is any chance avoid using the string to search any records, but you can achieve your expected output if you modify your query in this way using ILIKE :

SELECT id FROM product_attribute WHERE name ILIKE '%Legs%'

Avatar
Vazgeç
Üretici

Thanks for the reply,
I understand that using string to find a record is not a good practice and i am doing it for custom script to create a records from files so i do not have another option.
I think with there is risk while using ilike, if there is similar string or it is substring of other string then it will give me a wrong id.

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Mar 24
1767
1
Şub 23
2051
1
Ara 22
11646
6
Haz 15
7914
2
Şub 25
8541