Skip to content

postgres partition by hash failure #352

Closed

Description

@yarelm

Hi, Very cool project!

I have the following schema:

CREATE TABLE "user" (
    "id" uuid PRIMARY KEY,
    "other_id" uuid NOT NULL,
  ...
) PARTITION BY HASH (other_id);

CREATE TABLE "user_1" PARTITION OF "user" FOR VALUES WITH (MODULUS 10, REMAINDER 0); 

when I run sqlc generate I get the error message syntax error at or near "WITH"

I guess it has to do with hash partition introduced in Postgres 11

Any plans to make it work? Or any workaround?

Thanks

Activity

  1. kyleconroy commented on Feb 24, 2020

    @kyleconroy
    Collaborator

    sqlc relies on https://github.com/lfittl/pg_query_go, which currently uses the PostgreSQL 10 parser. The PARTITION BY HASH syntax was introduced in PostgreSQL 11. I've opened up an issue to get pg_query_go updated for PostgreSQL 11: https://github.com/lfittl/pg_query_go/issues/26

  2. yarelm commented on Mar 1, 2020

    @yarelm
    Author

    Thanks.
    Any workaround to get around this at this time?

    the partitioned table actually shouldn't relate to sqlc code generation, any way to make sqlc ignore this line?

  3. kyleconroy commented on Mar 1, 2020

    @kyleconroy
    Collaborator

    I was going to say that there isn't a workaround, but you can actually use the migration support to have sqlc ignore the CREATE TABLE "user_1" statement.

    CREATE TABLE "user" (
        "id" uuid PRIMARY KEY,
        "other_id" uuid NOT NULL,
      ...
    ) PARTITION BY HASH (other_id);
    
    -- +migrate Down
    CREATE TABLE "user_1" PARTITION OF "user" FOR VALUES WITH (MODULUS 10, REMAINDER 0); 

    I know this isn't an ideal solution, but it's the only current way to make it work. I may consider adding support for an -- ignore comment.

  4. added this to the v1.8.0 milestone on Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions