MCPcopy
hub / github.com/sqldef/sqldef / TestTypeKeywordsAsIndexColumns

Function TestTypeKeywordsAsIndexColumns

parser/parser_test.go:511–609  ·  view source on GitHub ↗

TestTypeKeywordsAsIndexColumns tests that type keywords (uuid, int, bigint, etc.) can be used as unquoted column names in index definitions

(t *testing.T)

Source from the content-addressed store, hash-verified

509// TestTypeKeywordsAsIndexColumns tests that type keywords (uuid, int, bigint, etc.)
510// can be used as unquoted column names in index definitions
511func TestTypeKeywordsAsIndexColumns(t *testing.T) {
512 testCases := []struct {
513 name string
514 sql string
515 shouldParse bool
516 description string
517 }{
518 // UNIQUE constraint with type keywords as column names
519 {
520 name: "UNIQUE constraint with uuid column",
521 sql: `ALTER TABLE "test" ADD CONSTRAINT "test_uuid_key" UNIQUE (uuid)`,
522 shouldParse: true,
523 description: "uuid should be usable as unquoted column name in UNIQUE constraint",
524 },
525 {
526 name: "UNIQUE constraint with int column",
527 sql: `ALTER TABLE "test" ADD CONSTRAINT "test_int_key" UNIQUE (int)`,
528 shouldParse: true,
529 description: "int should be usable as unquoted column name in UNIQUE constraint",
530 },
531 {
532 name: "UNIQUE constraint with bigint column",
533 sql: `ALTER TABLE "test" ADD CONSTRAINT "test_bigint_key" UNIQUE (bigint)`,
534 shouldParse: true,
535 description: "bigint should be usable as unquoted column name in UNIQUE constraint",
536 },
537 {
538 name: "UNIQUE constraint with json column",
539 sql: `ALTER TABLE "test" ADD CONSTRAINT "test_json_key" UNIQUE (json)`,
540 shouldParse: true,
541 description: "json should be usable as unquoted column name in UNIQUE constraint",
542 },
543 {
544 name: "UNIQUE constraint with varchar column",
545 sql: `ALTER TABLE "test" ADD CONSTRAINT "test_varchar_key" UNIQUE (varchar)`,
546 shouldParse: true,
547 description: "varchar should be usable as unquoted column name in UNIQUE constraint",
548 },
549 // PRIMARY KEY with type keywords
550 {
551 name: "PRIMARY KEY with uuid column",
552 sql: `ALTER TABLE ONLY "test" ADD CONSTRAINT "test_pkey" PRIMARY KEY (uuid)`,
553 shouldParse: true,
554 description: "uuid should be usable as unquoted column name in PRIMARY KEY",
555 },
556 // CREATE INDEX with type keywords
557 {
558 name: "CREATE INDEX on uuid column",
559 sql: `CREATE INDEX idx_uuid ON test (uuid)`,
560 shouldParse: true,
561 description: "uuid should be usable as unquoted column name in CREATE INDEX",
562 },
563 {
564 name: "CREATE UNIQUE INDEX on int column",
565 sql: `CREATE UNIQUE INDEX idx_int ON test (int)`,
566 shouldParse: true,
567 description: "int should be usable as unquoted column name in CREATE UNIQUE INDEX",
568 },

Callers

nothing calls this directly

Calls 2

ParseDDLFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected