From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Demitri Muna <postgresql(at)demitri(dot)com> |
Cc: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Getting "could not read block" error when creating an index on a function. |
Date: | 2020-12-30 16:50:27 |
Message-ID: | 2344514.1609347027@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Demitri Muna <postgresql(at)demitri(dot)com> writes:
> I’m getting stuck on a problem I was hoping I could get some help with. I’m trying to create an index for the results of a function that touches two tables like this and get the following error:
> CREATE INDEX my_idx ON mytable (first_time(id));
> ERROR: could not read block 0 in file "base/16386/42868": read only 0 of 8192 bytes
> CONTEXT: SQL function "first_time" during startup
What's apparently happening is that some query in the function is trying
to examine the newly-created index before it's been populated.
I would call this a bug if it were a supported case, but really you are
doing something you are not allowed to. Functions in indexed expressions
are required to be immutable, and a function that looks at the contents of
a table --- particularly the very table that the index is on --- is simply
not going to be that. Marking such a function immutable to try to end-run
around the restriction is unsafe.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Demitri Muna | 2020-12-30 19:37:59 | Re: Getting "could not read block" error when creating an index on a function. |
Previous Message | Tom Lane | 2020-12-30 16:41:14 | Re: Problem with ssl and psql in Postgresql 13 |