Skip to content

Add support for index opclass #129

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion __fixtures__/indexes/custom.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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) );
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 8 additions & 0 deletions packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down