diff --git a/__fixtures__/indexes/custom.sql b/__fixtures__/indexes/custom.sql index d800b2b..358ee9a 100644 --- a/__fixtures__/indexes/custom.sql +++ b/__fixtures__/indexes/custom.sql @@ -10,4 +10,6 @@ CREATE UNIQUE INDEX uniq_service_when_not_null ON schema2.table3 (uid, svc) WHERE svc IS NOT NULL; -CREATE UNIQUE INDEX new_unique_idx ON new_example(a, b) INCLUDE (c); \ No newline at end of file +CREATE UNIQUE INDEX new_unique_idx ON new_example(a, b) INCLUDE (c); + +CREATE INDEX CONCURRENTLY idx_with_operator ON boom.merkle_tree USING GIN ( name gin_trgm_ops ( param1 = 32, param2 = true) ); diff --git a/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap b/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap index c6550a8..7cdfc5f 100644 --- a/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap +++ b/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap @@ -25962,6 +25962,73 @@ exports[`kitchen sink indexes 9`] = ` exports[`kitchen sink indexes 10`] = `"CREATE UNIQUE INDEX new_unique_idx ON new_example ( a, b ) INCLUDE ( c );"`; +exports[`kitchen sink indexes 11`] = ` +{ + "RawStmt": { + "stmt": { + "IndexStmt": { + "accessMethod": "gin", + "concurrent": true, + "idxname": "idx_with_operator", + "indexParams": [ + { + "IndexElem": { + "name": "name", + "nulls_ordering": "SORTBY_NULLS_DEFAULT", + "opclass": [ + { + "String": { + "str": "gin_trgm_ops", + }, + }, + ], + "opclassopts": [ + { + "DefElem": { + "arg": { + "Integer": { + "ival": 32, + }, + }, + "defaction": "DEFELEM_UNSPEC", + "defname": "param1", + "location": 624, + }, + }, + { + "DefElem": { + "arg": { + "String": { + "str": "true", + }, + }, + "defaction": "DEFELEM_UNSPEC", + "defname": "param2", + "location": 637, + }, + }, + ], + "ordering": "SORTBY_DEFAULT", + }, + }, + ], + "relation": { + "inh": true, + "location": 575, + "relname": "merkle_tree", + "relpersistence": "p", + "schemaname": "boom", + }, + }, + }, + "stmt_len": 127, + "stmt_location": 526, + }, +} +`; + +exports[`kitchen sink indexes 12`] = `"CREATE INDEX CONCURRENTLY idx_with_operator ON boom.merkle_tree USING GIN ( name gin_trgm_ops ( param1 = 32, param2 = true ) );"`; + exports[`kitchen sink insert 1`] = ` { "RawStmt": { diff --git a/packages/deparser/src/deparser.ts b/packages/deparser/src/deparser.ts index 221112f..5faf76f 100644 --- a/packages/deparser/src/deparser.ts +++ b/packages/deparser/src/deparser.ts @@ -1548,6 +1548,14 @@ export default class Deparser { const output = []; if (node.name) { output.push(node.name); + if (node.opclass && node.opclass.length) { + output.push(this.deparse(node.opclass[0])); + } + if (node.opclassopts && node.opclassopts.length) { + output.push('('); + output.push(node.opclassopts.map((opclassopt) => this.deparse(opclassopt)).join(', ')); + output.push(')'); + } if (node.ordering === 'SORTBY_DESC') { output.push('DESC'); } else if (node.ordering === 'SORTBY_ASC') {