1

I want to import csv file into QuestDb table with designated timestamp column. I have to specify that one of the column is not a String but a Timestamp which I as

import requests
schema = '[{"name":"date", "type": "Timestamp", "pattern":"yyyy-MM-dd"}]'

with open('..\HavCases.csv', 'rb') as f:
    r = requests.post(r'http://localhost:9000/imp?name=table3&overwrite=true&timestamp=date',
        files={'schema': schema,'data': f})
    print(r.text)

but date column keep coming back as STRING and response is

not a timestamp 'date'

when I remove &timestamp from URL I see column parsed as STRING, not Timestamp

+-----------------------------------------------------------------------------------------------------------------+
|      Location:  |                                            table3  |        Pattern  | Locale  |      Errors  |
|   Partition by  |                                              NONE  |                 |         |              |
|      Timestamp  |                                              NONE  |                 |         |              |
+-----------------------------------------------------------------------------------------------------------------+
|   Rows handled  |                                               780  |                 |         |              |
|  Rows imported  |                                               780  |                 |         |              |
+-----------------------------------------------------------------------------------------------------------------+
...
|              9  |                                              date  |                   STRING  |           0  |

1 Answer 1

4

I found an aswer, it's not a trivial had to look into QuestDb source so posting it here for others

Apparently when QuestDb parses import request it expects 'schema' file to be first, before csv 'data'. When Python requests posts the data from files Dictionary it seems to post it in alphabetical order of the keys, so that files={'schema': schema,'data': f} and files={'data': f, 'schema': schema} are equivalent, data sent first and then schema.

To work around that I had to supply files parameter as list of tuples, not a dictionary:

with open(r'..\HavCases.csv', 'rb') as f:
    r = requests.post(r'http://localhost:9000/imp?name=table3&overwrite=true&timestamp=date', 
    files=[('schema', schema), ('data', f)])
    print(r.text)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.