Postgres point type support for insert queries
See original GitHub issueI am using kysely with the PostgresDialect
configuration as
const db = new Kysely<Database>({
dialect: new PostgresDialect({
pool,
}),
plugins: [new CamelCasePlugin()],
});
I am also using postgres point
type to store coordinates, which is of the format (x,y)
.
The cool thing is that the point type is transformed on queries to an object as {x, y}
which is way better to work with.
When inserting however like
db.insertInto("points").values({
location: {x: 4.4, y: 5.5}
}).execute();
I get an error like
“invalid input syntax for type point: "{"x":4.4,"y":5.5}"”.
So I have to manually parse the datatype like
const location = {x: 4.4, y: 5.5};
// @ts-ignore
db.insertInto("points").values({
location: `(${location.x},${location.y})`
}).execute();
which works correctly but introduces overhead and reduced typesafety.
Can we have the transformation also supported on insert or have a plugin at hand for this?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Insert POINT into postgres database - Stack Overflow
This works if you write SQL "directly": CREATE TEMP TABLE x(p point) ; INSERT INTO x VALUES ('(1,2)'); INSERT INTO x VALUES (point(3,...
Read more >Using point data type in insert statement - PostgreSQL
1. Create table with point data type. 2. Use Point data type in insert statement. 3. Using Point data type in a function ......
Read more >Documentation: 15: INSERT - PostgreSQL
INSERT inserts new rows into a table. One can insert one or more rows specified by value expressions, or zero or more rows...
Read more >PostgreSQL Data Types: Point
Continuing our series of PostgreSQL Data Types today we're going to introduce the PostgreSQL Point type. In order to put the Point datatype...
Read more >Insert point into point column in postgres/postgis
INSERT INTO points(coordinates) VALUES (ST_GeomFromText('POINT(10.809003 54.097834)',4326)); ERROR: column "coordinates" is of type point but ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tried this and it works:
This should actually work in all situations for that I can think of.
That works well. Thanks for the update!