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

Columns named as reserved words #388

Closed
alfonsodev opened this issue Nov 27, 2015 · 1 comment · Fixed by #422
Closed

Columns named as reserved words #388

alfonsodev opened this issue Nov 27, 2015 · 1 comment · Fixed by #422

Comments

@alfonsodev
Copy link

when a column name is a reserved word the generated query fails. In my case with a column called "end".

    CREATE SEQUENCE regions_id_seq;
    CREATE TABLE regions (
      "id"        integer NOT NULL DEFAULT nextval('regions_id_seq'),
      "start"     varchar(255),   
      "end"       varchar(255),
      "note"      varchar(255),   
      "id_song"   integer,           
      "version"   varchar(255),  
      "position"  integer,
      Constraint "regions_id_pkey" Primary Key ("id")
    );

postges error log

2015-11-27 21:19:33 UTC ERROR:  syntax error at or near "end" at character 111
2015-11-27 21:19:33 UTC STATEMENT:  WITH pg_source AS (UPDATE  public.regions  SET note='hello'::unknown,start='12'::unknown,id_song='2'::unknown,end='22'::unknown,version=null,position='10'::unknown  WHERE  public.regions.id = '17'::unknown  RETURNING public.regions.*) SELECT null, pg_catalog.count(t), null, null FROM ( SELECT  pg_source.* FROM  pg_source   LIMIT ALL OFFSET 0) t

In my situation I'll rename the column to "ending" but I though was good idea to report it.

@begriffs
Copy link
Member

Thanks for reporting this.

I bet it happens because pgFmtIdent does not add quotes to an identifier if the identifier contains no "dangerous" characters. Maybe if we have it add quotes all the time then the reserved words will work. I'll make a test case and try the fix.

calebmer added a commit to calebmer/postgrest that referenced this issue Dec 13, 2015
calebmer added a commit to calebmer/postgrest that referenced this issue Dec 13, 2015
begriffs added a commit that referenced this issue Dec 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants