Re: Query unable to utilize index without typecast to fixed length character

From: ahi <ahm3d(dot)hisham(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Query unable to utilize index without typecast to fixed length character
Date: 2023-04-07 07:09:06
Message-ID: CADaW2UO8J5TZUfCk5YWjMOabXTu3QO=hbFA4YC9Zc60wDKT8Yg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

You are right we should move from character(N) to text, however the
explicit typecast is also required for the numeric column not just the
character one

On Thu, Apr 6, 2023 at 4:50 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> ahi <ahm3d(dot)hisham(at)gmail(dot)com> writes:
> > CREATE TABLE public.marketplace_sale (
> > log_index integer NOT NULL,
> > created_at timestamp with time zone DEFAULT now() NOT NULL,
> > updated_at timestamp with time zone DEFAULT now() NOT NULL,
> > block_timestamp timestamp with time zone NOT NULL,
> > block bigint NOT NULL,
> > contract_address character(42) NOT NULL,
> > buyer_address character(42) NOT NULL,
> > seller_address character(42) NOT NULL,
> > transaction_hash character(66) NOT NULL,
> > quantity numeric NOT NULL,
> > token_id numeric NOT NULL,
> ...
>
> Type character(N) is a hangover from the days of punched cards.
> Don't use it. It has weird semantics concerning trailing spaces,
> which are almost never the behavior you actually want, and cause
> interoperability issues with type text. (Text is Postgres' native
> string type, meaning that unlabeled string constants will tend to
> get resolved to that.)
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message kunwar singh 2023-04-07 17:57:32 Is there any tool which will help me run and explain analyze about 150 queries?
Previous Message Tom Lane 2023-04-06 14:50:30 Re: Query unable to utilize index without typecast to fixed length character