Skip to main content
2 of 5
Spelling, link formatting.
RDFozz
  • 11.7k
  • 4
  • 24
  • 38

Find tables with two different indexes on same column in Postgresql DB

I am having an issue with scaffolding PostgreSQL db because npgsql does not handle tables with two index on same column well. Here's a link to my project on github.

I am trying to find these index / tables so I can exclude them from my scaffolding command.

I am trying to find tables similar to this.

CREATE TABLE public.altreproc
(
  apcod integer NOT NULL,
  aptip character(3),
  apcam character(3),
  CONSTRAINT altreproc_pkey PRIMARY KEY (apcod)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE public.altreproc
  OWNER TO postgres;

CREATE INDEX ialtreproc1
  ON public.altreproc
  USING btree
  (aptip COLLATE pg_catalog."default");

CREATE INDEX ialtreproc2
  ON public.altreproc
  USING btree
  (apcam COLLATE pg_catalog."default");

CREATE INDEX ialtreproc3
  ON public.altreproc
  USING btree
  (aptip COLLATE pg_catalog."default" DESC);

My problem is when a table has 2 different index with the same column (one ASC and one DESC); I am trying to query tables / indexes like this in db which I am trying to scaffold.

adopilot
  • 2.4k
  • 8
  • 31
  • 46