Replace EXECUTE PROCEDURE with EXECUTE FUNCTION because the former
is deprecated in PG11+. Unfortunately some test output will still
have EXECUTE PROCEDURE because pg_get_triggerdef in PG11 still
generates a definition with EXECUTE PROCEDURE.
When copying from standard input the range table was not set up to
handle the constraints for the target table and instead is initialized
to null. In addition, the range table index was set to zero, causing an
underflow when executing the constraint check. This commit fixes this
by initializing the range table and setting the index correctly.
The code worked correctly for PG12, so the code is also refactored to
ensure that the range table and index is set the same way in all
versions.
Fixes#1840
PG12 allows users to add a WHERE clause when copying from from a
file into a table. This change adds support for such clauses on
hypertables. Also fixes a issue that would have arisen in cases
where a table being copied into had a trigger that caused a row to
be skipped.
When using `COPY TO` on a hypertable (which copies from the hypertable
to some other destination), nothing will be printed and nothing will be
copied. Since this can be potentially confusing for users, this commit
print a notice when an attempt is made to copy from a hypertable
directly (not using a query) to some other destination.
Instead of freeing ChunkInsertStates immediately when flushed from the
SubspaceStore, defer the freeing until the es_per_tuple_exprcontext is
being cleaned up. This ensures that pointers into the CIS don't become
invalidated without us freeing any of postgres's memory, like we were
doing in the prior fix; this fixes a segfault in COPY.
In the normal INSERT case these frees happen at approximately the same
time so there should be no regression in memory usage, while if there
was a delay in freeing the es_per_tuple_exprcontext our old strategy of
clearing the context ourselves was invalid.
A change to the COPY test made the sort order ambiguous
for certain tuples, which breaks the test on some machines
where the sort order might differ from the expected one.
This fix makes the sort order more predictible.