pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedindices and casts
3+ messages / 2 participants
[nested] [flat]
* indices and casts
@ 2004-10-11 22:15 Rosser Schwarz <rosser.schwarz@gmail.com>
2004-10-11 22:32 ` Re: indices and casts Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: Rosser Schwarz @ 2004-10-11 22:15 UTC (permalink / raw)
To: pgsql-admin
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: indices and casts
2004-10-11 22:15 indices and casts Rosser Schwarz <rosser.schwarz@gmail.com>
@ 2004-10-11 22:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-10-11 22:48 ` Re: indices and casts Rosser Schwarz <rosser.schwarz@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2004-10-11 22:32 UTC (permalink / raw)
To: Rosser Schwarz <rosser.schwarz@gmail.com>; +Cc: pgsql-admin
Rosser Schwarz <rosser.schwarz@gmail.com> writes:
> 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 "::".
CREATE INDEX name ON table USING btree((column::date))
See the docs concerning indexes on expressions (formerly called
functional indexes). The parens are needed to avoid syntactic ambiguity
associated with the optional opclass name ...
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: indices and casts
2004-10-11 22:15 indices and casts Rosser Schwarz <rosser.schwarz@gmail.com>
2004-10-11 22:32 ` Re: indices and casts Tom Lane <tgl@sss.pgh.pa.us>
@ 2004-10-11 22:48 ` Rosser Schwarz <rosser.schwarz@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: Rosser Schwarz @ 2004-10-11 22:48 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-admin
while you weren't looking, Tom Lane wrote:
> CREATE INDEX name ON table USING btree((column::date))
Nested parens. D'oh.
It actually occurred to me to wonder if that might be the fix. But I
thought, nah, too easy.
Thanks once again, Tom.
/rls
--
:wq
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-10-11 22:48 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-10-11 22:15 indices and casts Rosser Schwarz <rosser.schwarz@gmail.com>
2004-10-11 22:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2004-10-11 22:48 ` Rosser Schwarz <rosser.schwarz@gmail.com>
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