@@ -350,7 +350,8 @@ def query(self,
350
350
database = None ,
351
351
raise_errors = True ,
352
352
chunked = False ,
353
- chunk_size = 0 ):
353
+ chunk_size = 0 ,
354
+ method = "GET" ):
354
355
"""Send a query to InfluxDB.
355
356
356
357
:param query: the actual query string
@@ -384,6 +385,9 @@ def query(self,
384
385
:param chunk_size: Size of each chunk to tell InfluxDB to use.
385
386
:type chunk_size: int
386
387
388
+ :param method: the HTTP method for the request, defaults to GET
389
+ :type method: str
390
+
387
391
:returns: the queried data
388
392
:rtype: :class:`~.ResultSet`
389
393
"""
@@ -401,9 +405,12 @@ def query(self,
401
405
if chunk_size > 0 :
402
406
params ['chunk_size' ] = chunk_size
403
407
408
+ if query .lower ().startswith ("select " ) and " into " in query .lower ():
409
+ method = "POST"
410
+
404
411
response = self .request (
405
412
url = "query" ,
406
- method = 'GET' ,
413
+ method = method ,
407
414
params = params ,
408
415
data = None ,
409
416
expected_response_code = expected_response_code
@@ -568,15 +575,17 @@ def create_database(self, dbname):
568
575
:param dbname: the name of the database to create
569
576
:type dbname: str
570
577
"""
571
- self .query ("CREATE DATABASE {0}" .format (quote_ident (dbname )))
578
+ self .query ("CREATE DATABASE {0}" .format (quote_ident (dbname )),
579
+ method = "POST" )
572
580
573
581
def drop_database (self , dbname ):
574
582
"""Drop a database from InfluxDB.
575
583
576
584
:param dbname: the name of the database to drop
577
585
:type dbname: str
578
586
"""
579
- self .query ("DROP DATABASE {0}" .format (quote_ident (dbname )))
587
+ self .query ("DROP DATABASE {0}" .format (quote_ident (dbname )),
588
+ method = "POST" )
580
589
581
590
def get_list_measurements (self ):
582
591
"""Get the list of measurements in InfluxDB.
@@ -602,7 +611,8 @@ def drop_measurement(self, measurement):
602
611
:param measurement: the name of the measurement to drop
603
612
:type measurement: str
604
613
"""
605
- self .query ("DROP MEASUREMENT {0}" .format (quote_ident (measurement )))
614
+ self .query ("DROP MEASUREMENT {0}" .format (quote_ident (measurement )),
615
+ method = "POST" )
606
616
607
617
def create_retention_policy (self , name , duration , replication ,
608
618
database = None , default = False ):
@@ -634,11 +644,11 @@ def create_retention_policy(self, name, duration, replication,
634
644
if default is True :
635
645
query_string += " DEFAULT"
636
646
637
- self .query (query_string )
647
+ self .query (query_string , method = "POST" )
638
648
639
649
def alter_retention_policy (self , name , database = None ,
640
650
duration = None , replication = None , default = None ):
641
- """Mofidy an existing retention policy for a database.
651
+ """Modify an existing retention policy for a database.
642
652
643
653
:param name: the name of the retention policy to modify
644
654
:type name: str
@@ -671,7 +681,7 @@ def alter_retention_policy(self, name, database=None,
671
681
if default is True :
672
682
query_string += " DEFAULT"
673
683
674
- self .query (query_string )
684
+ self .query (query_string , method = "POST" )
675
685
676
686
def drop_retention_policy (self , name , database = None ):
677
687
"""Drop an existing retention policy for a database.
@@ -685,7 +695,7 @@ def drop_retention_policy(self, name, database=None):
685
695
query_string = (
686
696
"DROP RETENTION POLICY {0} ON {1}"
687
697
).format (quote_ident (name ), quote_ident (database or self ._database ))
688
- self .query (query_string )
698
+ self .query (query_string , method = "POST" )
689
699
690
700
def get_list_retention_policies (self , database = None ):
691
701
"""Get the list of retention policies for a database.
@@ -751,16 +761,16 @@ def create_user(self, username, password, admin=False):
751
761
quote_ident (username ), quote_literal (password ))
752
762
if admin :
753
763
text += ' WITH ALL PRIVILEGES'
754
- self .query (text )
764
+ self .query (text , method = "POST" )
755
765
756
766
def drop_user (self , username ):
757
767
"""Drop a user from InfluxDB.
758
768
759
769
:param username: the username to drop
760
770
:type username: str
761
771
"""
762
- text = "DROP USER {0}" .format (quote_ident (username ))
763
- self .query (text )
772
+ text = "DROP USER {0}" .format (quote_ident (username ), method = "POST" )
773
+ self .query (text , method = "POST" )
764
774
765
775
def set_user_password (self , username , password ):
766
776
"""Change the password of an existing user.
@@ -796,7 +806,7 @@ def delete_series(self, database=None, measurement=None, tags=None):
796
806
tag_eq_list = ["{0}={1}" .format (quote_ident (k ), quote_literal (v ))
797
807
for k , v in tags .items ()]
798
808
query_str += ' WHERE ' + ' AND ' .join (tag_eq_list )
799
- self .query (query_str , database = database )
809
+ self .query (query_str , database = database , method = "POST" )
800
810
801
811
def grant_admin_privileges (self , username ):
802
812
"""Grant cluster administration privileges to a user.
@@ -808,7 +818,7 @@ def grant_admin_privileges(self, username):
808
818
and manage users.
809
819
"""
810
820
text = "GRANT ALL PRIVILEGES TO {0}" .format (quote_ident (username ))
811
- self .query (text )
821
+ self .query (text , method = "POST" )
812
822
813
823
def revoke_admin_privileges (self , username ):
814
824
"""Revoke cluster administration privileges from a user.
@@ -820,7 +830,7 @@ def revoke_admin_privileges(self, username):
820
830
and manage users.
821
831
"""
822
832
text = "REVOKE ALL PRIVILEGES FROM {0}" .format (quote_ident (username ))
823
- self .query (text )
833
+ self .query (text , method = "POST" )
824
834
825
835
def grant_privilege (self , privilege , database , username ):
826
836
"""Grant a privilege on a database to a user.
@@ -836,7 +846,7 @@ def grant_privilege(self, privilege, database, username):
836
846
text = "GRANT {0} ON {1} TO {2}" .format (privilege ,
837
847
quote_ident (database ),
838
848
quote_ident (username ))
839
- self .query (text )
849
+ self .query (text , method = "POST" )
840
850
841
851
def revoke_privilege (self , privilege , database , username ):
842
852
"""Revoke a privilege on a database from a user.
@@ -852,7 +862,7 @@ def revoke_privilege(self, privilege, database, username):
852
862
text = "REVOKE {0} ON {1} FROM {2}" .format (privilege ,
853
863
quote_ident (database ),
854
864
quote_ident (username ))
855
- self .query (text )
865
+ self .query (text , method = "POST" )
856
866
857
867
def get_list_privileges (self , username ):
858
868
"""Get the list of all privileges granted to given user.
0 commit comments