gocql icon indicating copy to clipboard operation
gocql copied to clipboard

QUERY ACCORDING TO DATE CONDITION

Open mertcakmak2 opened this issue 2 years ago • 2 comments

For example:

1) lastdate value is static ('2022-08-31 11:08') .

iter := Session.Query("SELECT * FROM students where lastdate>'2022-08-31 11:08' and firstname=? ALLOW FILTERING", name).Iter();

image

2) lastdate is variable and using in query.

lastdate := "2022-08-31 11:08"

iter := Session.Query("SELECT * FROM students where lastdate>? and firstname=? ALLOW FILTERING", lastdate, name).Iter()

image

What is problem in this query?

mertcakmak2 avatar Sep 01 '22 07:09 mertcakmak2

Do you get an error from the iterator? Please provide more context how you call the query and what the schema is.

Without more information my guess would be that you are trying to marshal a Go string into a timestamp cql type, which is not supported (see table at https://pkg.go.dev/github.com/gocql/gocql#Marshal). You could try using time.TIme, for example lastdate:=time.Date(2022,8,31,11,8,0,0,nil)

martin-sucha avatar Sep 02 '22 09:09 martin-sucha

Hi Martin no error in this query result or iterator. I haven't been try your example yet but I'll let you know when i try. Thank you for answer.

mertcakmak2 avatar Sep 03 '22 09:09 mertcakmak2