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

Support SYNONYMs in CREATE TABLE #125

Closed
apstndb opened this issue Oct 1, 2024 · 8 comments · Fixed by #172
Closed

Support SYNONYMs in CREATE TABLE #125

apstndb opened this issue Oct 1, 2024 · 8 comments · Fixed by #172

Comments

@apstndb
Copy link
Contributor

apstndb commented Oct 1, 2024

SYNONYMs in CREATE TABLE has not yet been supported.

https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#create_table

CREATE TABLE [ IF NOT EXISTS ] table_name ( [
   { column_name data_type [NOT NULL]
     [ { DEFAULT ( expression ) | AS ( expression ) [ STORED ]
       | table_constraint | synonym_definition ]
     [ options_def ]
     [ location_name STRING(MAX) NOT NULL PLACEMENT KEY ]
   [, ... ]
] ) PRIMARY KEY ( [column_name [ { ASC | DESC } ], ...] )
[, INTERLEAVE IN PARENT table_name [ ON DELETE { CASCADE | NO ACTION } ] ]
[, ROW DELETION POLICY ( OLDER_THAN ( timestamp_column, INTERVAL num_days DAY ) ) ]

...

and synonym_definition is:
    [ SYNONYM (synonym [, synonym...])]

Related: #115

@makenowjust
Copy link
Collaborator

The document says: synonym_definition is: [SYNONYM (synonym [, synonym...])], but Cloud Spanner does not accept multiple synonym identifiers in a single synonym definition.

スクリーンショット 2024-10-19 22 23 32

@apstndb
Copy link
Contributor Author

apstndb commented Oct 19, 2024

I have curious about what is displayed in getDdl or gcloud spanner databases ddl describe after adding multiple SYNONYMs using ALTER TABLE ALTER COLUMN ADD SYNONYM

@apstndb
Copy link
Contributor Author

apstndb commented Oct 19, 2024

I have noticed there are no ALTER TABLE ALTER COLUMN ADD SYNONYM. There is only ALTER TABLE ADD SYNONYM synonymandALTER TABLE RENAME TO new_table_name`.

@makenowjust
Copy link
Collaborator

The last expression in the screen shot is failed, and I guess only the last synonym is available.

スクリーンショット 2024-10-19 22 51 03

@apstndb
Copy link
Contributor Author

apstndb commented Oct 19, 2024

spanner> CREATE TABLE t(PK INT64, SYNONYM(alias1)) PRIMARY KEY(PK);
Query OK, 0 rows affected (6.78 sec)

spanner> SHOW CREATE TABLE t;
+-------+--------------------+
| Table | Create Table       |
+-------+--------------------+
| t     | CREATE TABLE t (   |
|       |   PK INT64,        |
|       |   SYNONYM(alias1), |
|       | ) PRIMARY KEY(PK)  |
+-------+--------------------+
1 rows in set (0.80 sec)

spanner> ALTER TABLE t ADD SYNONYM alias2;
ERROR: rpc error: code = FailedPrecondition desc = Cannot add a synonym t for alias2. A synonym already exists for this table.

@apstndb
Copy link
Contributor Author

apstndb commented Oct 19, 2024

spanner> CREATE TABLE t2(PK INT64, SYNONYM(alias21), SYNONYM(alias22)) PRIMARY KEY(PK);
Query OK, 0 rows affected (7.51 sec)

spanner> SHOW CREATE TABLE t2;
+-------+---------------------+
| Table | Create Table        |
+-------+---------------------+
| t2    | CREATE TABLE t2 (   |
|       |   PK INT64,         |
|       |   SYNONYM(alias22), |
|       | ) PRIMARY KEY(PK)   |
+-------+---------------------+
1 rows in set (0.77 sec)

Only the last synonym is enabled.

@apstndb
Copy link
Contributor Author

apstndb commented Oct 19, 2024

I don't think it is documented behavior. I will feed back to Google.

@apstndb
Copy link
Contributor Author

apstndb commented Oct 23, 2024

I have noticed the documented DDL syntax is fixed.

https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#create_table

and synonym_definition is:
    [ SYNONYM (synonym) ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants