-
Notifications
You must be signed in to change notification settings - Fork 318
Description
Thank you for this project! I was very glad to stumble upon it.
I've got a use case where I need to dynamically create database columns from a json file. This json file contains the names and types of each column. E.g:
[
{ "name": "TEMP", "type": "uint8" },
{ "name": "VOLTAGE", "type": "flt16" }
]
I then map these types into data types supported by Postgres. E.g. uint8
becomes int2
and flt16
becomes real
.
After this, I feed those names and mapped data types into an await sql`ALTER TABLE X ADD COLUMN ${ sql( name ) } ${ sql(mappedType) }`
command using postgres.js.
The issue is that one of my types maps to the postgres type bit(4)
, but postgres.js does not seem to parse this correctly and I get a postgres error: code 42704: type: ''bit(4)'' does not exist
. I am suspicious about the double quoting going on here and assume that the sql method does not like to parse strings with parentheses. Escaping the parentheses did not help.
I appreciate any help or thoughts on the issue.