Re: [SQL] Index on date_trunc
От | Tom Lane |
---|---|
Тема | Re: [SQL] Index on date_trunc |
Дата | |
Msg-id | 19798.925739574@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: [SQL] Index on date_trunc (Herouth Maoz <herouth@oumail.openu.ac.il>) |
Ответы |
Re: [SQL] Index on date_trunc
|
Список | pgsql-sql |
Herouth Maoz <herouth@oumail.openu.ac.il> writes: > At 08:19 +0300 on 30/04/1999, Christophe Labouisse wrote: >> create index ns_dt1_idx on netstats (date_trunc('day',NS_DATE) datetime_ops); > Seems as if the syntax requires that all the arguments for the function > should be attributes. Yes, I believe that's the case. It's not only the parser that's limited, either: the physical representation of indices doesn't currently have room for anything more than a function OID to define what the index sort function is. So there's noplace to put a constant value. > Solution: create a function that hides the 'day' in it: Good thought, but it doesn't actually work, as you'll find as soon as there are any entries in the table: insert into test values ('1999-08-01 10:15'); ERROR: SQL-language function not supported in this context. (6.4.x gives a misleading error message, but it's the same restriction.) It'd be nice to allow SQL functions to be used for indexes, but I'm not sure what it'd take to make it happen. At the very least there'd have to be some drastic restrictions on what the function could do (imagine the carnage if the function tries to modify the table the index is being built for...) Bottom line is there's no easy way to do this right now :-(. What I'd suggest is keeping a separate column that is the day part of the date and indexing that. You could use a rule to update that column automatically whenever the main timestamp column is set. Alternatively, try to restructure your queries so that you don't actually need an index on the day part of the date... regards, tom lane
В списке pgsql-sql по дате отправления: