mustafasrepo commented on code in PR #7160:
URL: https://github.com/apache/arrow-datafusion/pull/7160#discussion_r1281471141
##########
datafusion/sql/tests/sql_integration.rs:
##########
@@ -233,6 +233,25 @@ fn plan_create_table_with_pk() {
let sql = "create table person (id int, name string, primary key(id))";
let plan = r#"
CreateMemoryTable: Bare { table: "person" } constraints=[PrimaryKey([0])]
+ EmptyRelation
+ "#
+ .trim();
+ quick_test(sql, plan);
+
+ let sql = "create table person (id int primary key, name string)";
+ let plan = r#"
+CreateMemoryTable: Bare { table: "person" } constraints=[PrimaryKey([0])]
+ EmptyRelation
+ "#
+ .trim();
+ quick_test(sql, plan);
+}
+
+#[test]
+fn plan_create_table_with_multi_pk() {
+ let sql = "create table person (id int, name string primary key, primary
key(id))";
Review Comment:
> I am not sure this means a multi part primary key -- postgres errors on
this syntax
>
> ```sql
> postgres=# create table person (id int, name varchar primary key, primary
key(id));
> ERROR: multiple primary keys for table "person" are not allowed
> LINE 1: ...e table person (id int, name varchar primary key, primary ke...
> ```
>
> I think the way this is supposed to be expressed is like
>
> ```sql
> create table person (id int, name varchar, primary key(name, id));
> ```
I would expect that `name` is primary key, and `id` is primary key (they
each consists of unique values, unlike their tuple version is unique which is
also the case.) for the query
```sql
create table person (id int, name string primary key, primary key(id))
```
In short, when one want to use composite primary key, they have to use
```sql
create table person (id int, name varchar, primary key(name, id));
```
syntax. However, for defining single primary keys, they have alternative
version. However, if this behaviour is misleading, or counter intuitive. We can
follow postgres and give an error. However, It seems to me that, there is no
reason to restrain.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]