Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
Create index on composite type in Postgres

I am running Postgres 12 I have an audit field composite type I made for keeping my tables from being too fat.

    create type adt_flds as
(
    created_at timestamp,
    updated_at timestamp,
    created_by text,
    updated_by text,
    created_by_client_addr inet,
    updated_by_client_addr inet,
    created_by_client_cmptr text,
    updated_by_client_cmptr text
);

   create table if not exists excel.equip_type
   (
       equip_type_id serial not null constraint equip_type_pk primary key,
       descrip text,
       adt_flds adt_flds 
   );

--Creates a syntax error
create index equip_type_adt_flds_index
    on excel.equip_type (adt_flds.created_at);

I am to the point where I would like to index the created_at field so when I filter on created_at in my WHERE statements, my queries can index scan and not heap scan. My issue is that I end up with a syntax error on my create index statement. How would I fix my syntax up so I can have an index on a just 1 element of my adt_flds type?

[42601] ERROR: syntax error at or near ")" Position: 85

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The PostgreSQL documentation is pretty clear about the syntax for indexes that are created on an expression rather than a table column:

The expression usually must be written with surrounding parentheses, as shown in the syntax. However, the parentheses can be omitted if the expression has the form of a function call.

You need additional parentheses for disambiguation.

Try

CREATE INDEX equip_type_adt_flds_index
   ON excel.equip_type (((adt_flds).created_at));
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!