New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INSERT complex types into a PostgreSQL table. #25
Comments
Here is the full code with @database/pg
This fails on the insert statement with all kinds of errors. And here is the same script using the pg module.
This works A-OK. |
I think you want something like: db.query(sql`
INSERT INTO dev.jack_wolfskin (id, city, store, lat, lng, geom)
VALUES (
${parseInt(store.id)},
${store.city},
${store},
${parseFloat(store.lat)},
${parseFloat(store.lng)},
ST_SetSRID(ST_Point(${parseFloat(store.lng)}, ${parseFloat(store.lat)}), 4326)'
)
`) There are three problems with your original code:
I hope this helps. |
Thanks Forbes that works perfectly fine. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am able to select and insert text and numbers into a PostgreSQL table, but anything more complex fails.
For example this template literal produces completely legit SQL which can copy into the command line for execution.
The table schema is as follows:
I have tried to break it down but I have no clue how to insert json type or geometry type generated from a function.
This works pretty well node postgres so there must be something in the atdatabase wrapper which I don't understand.
It would be great if you can provide an example as I would like to do more testing with this product.
The text was updated successfully, but these errors were encountered: