pgtyped
pgtyped copied to clipboard
Allow mappings within parameter expansions
Given the following table
CREATE TABLE postal_codes (
updated_at timestamp NOT NULL,
created_at timestamp NOT NULL,
location point NULL,
code text NOT NULL
);
I would like to insert a new row { code: '111111', latitude: '1.2.3.4', longitude: '4.5.6.7' }
but need for coerce given latitude/longitude coordinates into a single postgres Point datatype
/* @name insertPostalCodes */
INSERT INTO postal_codes (code,, location, created_at, updated_at)
VALUES (:code!, POINT(:latitude!, :longitude!), NOW(), NOW());
But I'll be inserting many many rows and would like to insert multiple in a single query to avoid the network round trips. However array spread and pick does not support mapping the incoming values in any way. I would like to do something like this so I can provide the entire array's worth of data up front while still mapping longitude/latitude into a single Point.
/*
@name insertPostalCodes
@param zips -> ((code!, latitude!, longitude!)...)
*/
INSERT INTO postal_codes (code, location, created_at, updated_at)
VALUES (:zips(code, POINT(latitude, longitude)), NOW(), NOW())