From: Rosser Schwarz <rosser.schwarz@gmail.com>
To: pgsql-admin@postgresql.org
Subject: indices and casts
Date: Mon, 11 Oct 2004 17:15:41 -0500
Message-ID: <37d451f704101115152fa2acc8@mail.gmail.com> (raw)
I have a number of timestamp columns on various tables I'd like also
to be able to query against as dates. I can easily enough say "SELECT
* FROM foo WHERE bar::date = '2004-10-11'" and the like, but such
queries are inevitably sequential scans, and the tables are rather
large for that to be as performant as I'd like.
Is it possible to do something functionally equivalent to "CREATE
INDEX name ON table USING btree(column::date)"? That statement yields
a syntax error on the "::". Trying to create the index using the
date_ops opclass yields an error to the effect that date_ops don't
work on timestamp values.
The only alternatives I can see are: to issue queries of the form
"SELECT foo FROM bar WHERE baz BETWEEN '2004-10-11' AND '2004-10-12'",
which is do-able, since most of our SQL is generated, but awkward and
prone to being forgotten in the odd case where it's not generated; or
adding another column of type date, which seems awkward and prone to
causing confusion between the date and timestamp columns. What am I
missing (alternatively, what am I smoking)? 7.4.2 on RH9, if it
helps.
/rls
--
:wq
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: rosser.schwarz@gmail.com
Subject: Re: indices and casts
In-Reply-To: <37d451f704101115152fa2acc8@mail.gmail.com>
References: <37d451f704101115152fa2acc8@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox