Search code examples
amazon-web-servicesamazon-redshiftamazon-redshift-spectrum

Redshift Spectrum gives syntax error on creating nested data


I am using this query

CREATE EXTERNAL TABLE test.post(
      edge_media_to_tagged_user struct<
            "edges": array<
            "node": struct<
                "user": struct<
                  id:bigint,
                  username:text
                >,
                x: float(24),
                y: float(24)
            >
        >
      >
  )
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
LOCATION 's3://bucket/test';

Somehow the query above gives me

ERROR:  syntax error at or near ":"
LINE 4:             "node": struct<

Removing or adding colon and/or double quote still gives me the error.

Any help is appreciated!


Solution

  • Answer from John gives an important hint, this code work

    
    CREATE EXTERNAL TABLE likes_schema_test.post88(
          edge_media_to_tagged_user struct<
            "edges": array<struct<      <-- change here
                "node": struct<
                    "user": struct<
                      full_name:text,
                      id:bigint,
                      is_verified: boolean,
                      username:text
                    >,
                    x: float(24),
                    y: float(24)
                >>
            >
          >
      )
    ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
    LOCATION 's3://follower-dumper-testing/post_test';
    

    Changing "node" to 'node' would give a syntax error.