Skip to content
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

Support of column identifiers with "special" characters #462

Closed
user318 opened this issue Jan 17, 2016 · 9 comments
Closed

Support of column identifiers with "special" characters #462

user318 opened this issue Jan 17, 2016 · 9 comments
Labels

Comments

@user318
Copy link

user318 commented Jan 17, 2016

I have column name "nic-hdl" in my table. When I make request to all columns (http://localhost:3000/person) - I receive answer as expected. But if I'm trying to specify this column in select (http://localhost:3000/person?select=nic-hdl), than I get an error:
HTTP/1.1 400 Bad Request
...
{"details":"unexpected "h" expecting "->>"","message":""failed to parse select parameter <>" (line 1, column 4)"}

It will be good if there will be a way to quote identifiers. Postgres allows to use such identifiers by quoting them with double qoutes "".

@user318 user318 changed the title Suppor of column identifiers with "special" characters Support of column identifiers with "special" characters Jan 17, 2016
@calebmer
Copy link
Contributor

PostgREST quotes all identifiers, even the ones which don't need it. The problem is with the PostgREST select query parser which doesn't allow the - character. This should be an easy fix @begriffs if you want to add the tag.

@calebmer
Copy link
Contributor

Here's the specific line which only allows letters, numbers and _.

@begriffs begriffs added the difficulty: beginner Pure Haskell task label Jan 17, 2016
@calebmer
Copy link
Contributor

@ruslantalpa I tried fixing this, but it requires a little more parser work that I'm not able to do. When I add - to the oneOf list on the line above, the parser captures expressions like data- in data->x->y->>z. Is there a good fix for this?

@ruslantalpa
Copy link
Contributor

see if this works

pFieldName :: Parser Text
pFieldName =  cs <$> (
     ((many1 (letter <|> digit)) `sepBy` (oneOf "_-"))
      <?> "field name (* or [a..z0..9_])"
    )

@SebAlbert
Copy link

I think you should really try to implement quoting within the select parameter. It's only a matter of time until somebody with a comma or -> in a column name would show up...

@begriffs
Copy link
Member

begriffs commented Apr 3, 2016

Anyone want to push this over the finish line and send a PR?

@begriffs begriffs added the bug label Apr 3, 2016
@begriffs
Copy link
Member

I created a failing test to demonstrate the problem on branch hyphenated-cols. @ruslantalpa the suggested pFieldName doesn't work because it tries parsing [String] which cs can't convert to Text.

@ghost
Copy link

ghost commented Oct 30, 2017

@SebAlbert Good point.
I am using a mediawiki api and a key column is called *. It fails, in the select list and in the "where" list. I expected that quoting identifiers should work :(

@steve-chavez
Copy link
Member

Related to #1008.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

6 participants