Re: [SQL] indexing a datetime by date

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
Cc: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>, Andrew Merrill <andrew(at)compclass(dot)com>, pgsql-sql(at)hub(dot)org, PGSQL Hackers <pgsql-hackers(at)hub(dot)org>
Subject: Re: [SQL] indexing a datetime by date
Date: 1999-03-30 16:31:35
Message-ID: 6913.922811495@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu> writes:
>> create index when_ndx3 on notes (date(when) date_ops);
>> Which won't work because the date(datetime) function isn't trusted.

> Tom, does this ring a bell with you?

No, and in fact datetime_date *is* marked trusted in pg_proc,
both current sources and 6.4.2.

I see the problem DeJuan is getting at:

play=> create table notes (when datetime);
CREATE
play=> create index when_ndx3 on notes (date(when) date_ops);
CREATE
play=> insert into notes values ('now');
ERROR: internal error: untrusted function not supported.

This is either a bug or a very poorly worded error message.
I'll look into it.

In the meantime, a workaround is to call the function using its
builtin name:

play=> create table notes (when datetime);
CREATE
play=> create index when_ndx3 on notes (datetime_date(when) date_ops);
CREATE
play=> insert into notes values ('now');
INSERT 1086489 1

In 6.4.2, date() on a datetime is an SQL-language function that just
calls the builtin function datetime_date(). It would seem that 6.4.2
can't cope with an SQL-language function as an index generator. This
might be a minor bug or it might be difficult to change; I dunno.

In 6.5, date() on a datetime is a true builtin, on par with
datetime_date(), so you'll be able to use either name interchangeably in
that release. But we may still not be able to do anything with other
SQL-language functions as index generators.

regards, tom lane

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Lockhart 1999-03-30 16:37:50 Re: [HACKERS] Regression failures
Previous Message Michael Davis 1999-03-30 16:11:57 Views, aggregations, and errors

Browse pgsql-sql by date

  From Date Subject
Next Message Jackson, DeJuan 1999-03-30 17:21:12 RE: [SQL] indexing a datetime by date
Previous Message Oliver Smith 1999-03-30 16:00:33 Date operation efficiency