Unsupported type (bytea) in BINARY inserts
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.3k
- Forks
- 1.6k
- Avg merge
- 5d 10h
- Merged PRs (30d)
- 28
Description
Describe the bug
When inserting binary data, QuestDB throws unsupported type error for the bytea type.
To Reproduce
Inserting b string using psycopg2 via Python:
import psycopg2
import datetime
connection = psycopg2.connect(
user="admin",
password="quest",
host="127.0.0.1",
port="8812",
database="qdb")
cursor = connection.cursor()
try:
cursor = connection.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS binary_table (ts TIMESTAMP, name STRING, binary_data BINARY) timestamp(ts);")
connection.commit()
dt = datetime.datetime.utcnow()
timestamp = dt.strftime('%Y-%M-%dT%H:%M:%S.%s')
cursor.execute("INSERT INTO binary_table VALUES (%s,%s,%s))", (timestamp, 'Hello', b'b string'))
connection.commit()
print (cursor.rowcount, "Successfully inserted")
except(Exception, psycopg2.Error) as error:
print("Error connecting to QuestDB", error)
connection = None
finally:
if(connection != None):
cursor.close()
connection.close()
print("Connection closed")
Error:
Error connecting to QuestDB unsupported type
LINE 1: ...T11:02:26.1625475746','Hello','\\x6220737472696e67'::bytea))
^
When using the psychopg2 wrapper for binary data, this will also fail:
bin_data = open('test.png', 'rb').read()
cursor.execute("INSERT INTO binary_table VALUES (%s,%s,%s))", (timestamp, 'Hello', psycopg2.Binary(bin_data)))
err:
Error connecting to QuestDB unsupported type
LINE 1: ...b500e0ff0115c59a6b736d62550000000049454e44ae426082'::bytea))
^
Environment (please complete the following information):
- OS: macOS 11.04
- Version: 6.0.3
Additional context
Note that prepared statements instead of inserting hex strings directly fails using Node.js pg package:
const { Client } = require("pg");
const fs = require("fs");
const buffer = fs.readFileSync("./test.png");
const start = async () => {
try {
const client = new Client({
database: "qdb",
host: "127.0.0.1",
password: "quest",
port: 8812,
user: "admin",
});
await client.connect();
const createTable = await client.query(
"CREATE TABLE IF NOT EXISTS binary_table_2 (name STRING, value BINARY);"
);
console.log(createTable);
// Providing a 'name' field allows for prepared statements / bind variables
const query = {
name: "insert-values",
text: "INSERT INTO binary_table_2 VALUES($1, $2);",
values: ["node binary insert", buffer],
};
const preparedStatement = await client.query(query);
await client.query("COMMIT");
await client.end();
} catch (e) {
console.log(e);
}
};
start();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files or tests are named. Reproduce the BINARY insert with psycopg2 and Node.js pg, then trace the PostgreSQL-compatible insert handling for the bytea cast and prepared bind value. Done means both client examples insert binary data successfully without an unsupported type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, postgresql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100