-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Feature request: Add ability to cast an input argument in a POST before INSERT #1670
Comments
But you already know that - that's why you are using it. We are using it as well to process the json body: postgrest/src/PostgREST/QueryBuilder.hs Line 74 in 9adec12
If your target table's column is set to your custom type - there is no reason to assume this wouldn't work out of the box. No cast needed. Does it not work for you? |
Related to this gitter thread. In general I think it'd be simple to add. But I'm failing to come up with a use case because, as Wolfgang mentions, casting should already work thanks to |
I don't think so. We don't touch the json before We can't hook into the casting that @a-mckinley Did you try just inserting without any custom casts? |
@wolfgangwalther I thought of casting it after INSERT INTO "test"."projects" ("id", "name")
SELECT
"id"::smallint, -- cast here
"name"
FROM json_populate_recordset (NULL:: "test"."projects" , (SELECT val FROM pgrst_body)) _ RETURNING "test"."projects".*;
But yes, I'm also not seeing the use case. I was mostly thinking of #1597 (comment) (transforming the inputs with a function before the INSERT) when coming up with the implementation. |
What about something like #1661 (comment)? Specifically this part:
This is under the assumption, that we move the pre request function in a CTE of the main query together with the
(note the Having a chance to do a transformation before |
A suggestion for that is tracked in #1661 (comment). Everything else in here seems set.
If that doesn't work for you, feel free to re-open. |
@wolfgangwalther The The However as I mentioned before, I fail to see the use case where our |
hi @wolfgangwalther and @steve-chavez. Thanks for talking this one through. You were absolutely correct that |
Hi all, I've just started looking at postgREST and looks fantastic, but I was looking for handling postGIS extension geometry types. Generally you have a geometry type and consume geoJson representation using to_geojson and from_geojson functions. |
Hey @massimiliano-cannata, can you see if PostgREST/postgrest-docs#273 (comment) helps? |
Hi,
I have a custom postgres type that is nested and relatively complex so I used
jsonb_populate_record()
server-side to create instances of this type from a json representation.Currently to INSERT to this table from I would use a custom written server-side function to wrap the call to
jsonb_populate_record()
.It would be very convenient and versatile if PostgREST allowed you to apply a cast to input arguments e.g.
which would hopefully apply a server-side cast created with
Is such an enhancement possible? I think it could rather cleanly reduce the amount of specific server-side code needed in this case, but potentially has other uses that I haven't thought of yet.
The text was updated successfully, but these errors were encountered: