Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Vertical filtering on inserts #130

Closed
rvernica opened this issue Apr 25, 2018 · 4 comments
Closed

Vertical filtering on inserts #130

rvernica opened this issue Apr 25, 2018 · 4 comments

Comments

@rvernica
Copy link

For insertions, the docs talk about using Prefer: return=representation to get the inserted object back. Moreover they also talk about applying vertical filtering to it, e.g., ?select=foo.

Where would one specify the select=foo part in the POST request of an insert operation?

@steve-chavez
Copy link
Member

Would be in the querystring as usual, if I'm understanding you correctly, there's an example here https://github.com/begriffs/postgrest/blob/master/test/Feature/InsertSpec.hs#L41-L50.

it "filters columns in result using &select" $
  request methodPost "/menagerie?select=integer,varchar" [("Prefer", "return=representation")]
    [json| [{
      "integer": 14, "double": 3.14159, "varchar": "testing!"
    , "boolean": false, "date": "1900-01-01", "money": "$3.99"
    , "enum": "foo"
    }] |] `shouldRespondWith` [str|[{"integer":14,"varchar":"testing!"}]|]
    { matchStatus  = 201
    , matchHeaders = [matchContentTypeJson]
    }

@rvernica
Copy link
Author

Thanks for the pointer. I think I got the syntax right, but it seems that the primary key needs to be among the values in the select list. Is that the case?

For example, after the setup in Tutorial 0, I can do:

> curl "http://localhost:3000/todos?select=id" -X POST -H "Content-Type: application/json" -H "Prefer: return=representation" -d '{"task": "do bad thing"}'
[{"id":8}]%                                                                                                                                         

> curl "http://localhost:3000/todos?select=id,task" -X POST -H "Content-Type: application/json" -H "Prefer: return=representation" -d '{"task": "do bad thing"}'
[{"id":9,"task":"do bad thing"}]%

But I cannot do:

> curl "http://localhost:3000/todos?select=task" -X POST -H "Content-Type: application/json" -H "Prefer: return=representation" -d '{"task": "do bad thing"}'
{"details":"Row number 0","message":"Row error: unexpected null"}%  

@steve-chavez
Copy link
Member

Yeah, that's a bug reported in PostgREST/postgrest#1087, this will be fixed on the next release.

@steve-chavez
Copy link
Member

v5.0 was released some time ago, I'll close this one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants