Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Unexpected behaviour in Python API: time should be in quotes in select #309

Closed
@Jimilian

Description

@Jimilian

I found that if you are using simple select query "select * from measurement where t = X" without quotes, result becomes unpredictable. For it's unclear why I should use quotes for time, if time is integer (or long).

from time import sleep
from influxdb import client as influxdb

db = influxdb.InfluxDBClient("localhost", 8086, "", "", "queue")

measurement = "wtr"

def drop():
    db.query("drop measurement " + measurement)

def show_all():
    print db.query("select * from " + measurement)

def check_one_way(t):
    result = db.query('select * from {0} where time="{1}"'.format(measurement, t))
    return bool(result)

def check_second_way(t):
    result = db.query('select * from {0} where time={1}'.format(measurement, t))
    return bool(result)

def write_to_influx(exists):
    t = 1458239131231000000
    points = [{'fields': {'value': 1}, 'time': t, 'measurement': measurement}]

    if exists(t):
        print "Exists!!!", t
        return

    db.write_points(points)

    sleep(1)

    if exists(t):
        print "OK"  # Expected behaviour
    else:
        print "WTF?!"  # Unexpected behaviour

print "With quotes"
write_to_influx(check_one_way)
show_all()
print "="*80

print "Without quotes"
drop()
write_to_influx(check_second_way)
show_all()
drop()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions