The @> operator (contains) is defined only for JSONB; your original message said you were using JSONB. However, this error says your column is just JSON. These two types are not the same thing; you should use JSONB if you have a choice.
On Thu, Dec 31, 2015, at 03:43 PM, Sami Pietilä wrote: > Perhaps there is something wrong with my select. I tried with following > select and got an error message below: > select([database.tables['jtable'].c['data']]).where(database.tables['jtable'].c['data'].contains('third')) > > --- Error Message --- > sqlalchemy.exc.DataError: (psycopg2.DataError) invalid input syntax for > type json > LINE 3: WHERE jtable.data @> 'third' > ^ > DETAIL: Token "third" is invalid. > CONTEXT: JSON data, line 1: third > [SQL: 'SELECT jtable.data \nFROM jtable \nWHERE jtable.data @> > %(data_1)s'] [parameters: {'data_1': 'third'}] > > > torstai 31. joulukuuta 2015 16.11.47 UTC+2 Jon Rosebaugh kirjoitti: > > > > Your SQL itself isn't going to work; there's no 'item' column in your > > select statement. You should read > > http://www.postgresql.org/docs/9.4/interactive/functions-json.html to > > see what operators you have. (I think you want '@>', not LIKE.) > > > > In SQLAlchemy, this would be done as > > .where(mytable.c['data'].contains('third')). > > > > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.