문제

I have a table for which I want to define a composite primary key with two columns in redshift. I am having some trouble with create table syntax. Here is what I am trying to do :

Create table metrics  (
     id varchar(30),
     runtime timestamp,
     category varchar(30),
     location varchar(30))
primary key(id, runtime),
sortkey(runtime);

It is failing with a message :

ERROR:  syntax error at or near "PRIMARY"

Can anyone please help me figure out how to fix it? Thanks in advance.

도움이 되었습니까?

해결책

The primary key constraint goes inside the parentheses containing the columns:

Create table metrics  (
     id varchar(30),
     runtime timestamp,
     category varchar(30),
     location varchar(30),
     primary key(id, runtime)
)
sortkey(runtime);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top