Re: Virtual generated columns - Mailing list pgsql-hackers

From jian he
Subject Re: Virtual generated columns
Date
Msg-id CACJufxGh=XX7q5xTci---HikSJsOwP7_qCNyyDHdp2YL4NLZCg@mail.gmail.com
Whole thread Raw
In response to Re: Virtual generated columns  (Peter Eisentraut <peter@eisentraut.org>)
Responses Re: Virtual generated columns
List pgsql-hackers
statistic related bug.
borrow examples from
https://www.postgresql.org/docs/current/sql-createstatistics.html

CREATE TABLE t3 (a   timestamp PRIMARY KEY, b timestamp GENERATED
ALWAYS AS (a) VIRTUAL);
CREATE STATISTICS s3 (ndistinct) ON b FROM t3;
INSERT INTO t3(a) SELECT i FROM generate_series('2020-01-01'::timestamp,
                                             '2020-12-31'::timestamp,
                                             '1 minute'::interval) s(i);
ANALYZE t3;
CREATE STATISTICS s3 (ndistinct) ON date_trunc('month', a),
date_trunc('day', b) FROM t3;
ANALYZE t3;
ERROR:  unexpected virtual generated column reference



--this is allowed
CREATE STATISTICS s5 ON (b + interval '1 day') FROM t3;
--this is not allowed. seems inconsistent?
CREATE STATISTICS s6 ON (b ) FROM t3;


in CreateStatistics(CreateStatsStmt *stmt)
we have

if (selem->name)
{
            if (attForm->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL)
                ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                         errmsg("statistics creation on virtual
generated columns is not supported")));
}
else if (IsA(selem->expr, Var)) /* column reference in parens */
{
            if (get_attgenerated(relid, var->varattno) ==
ATTRIBUTE_GENERATED_VIRTUAL)
                ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                         errmsg("statistics creation on virtual
generated columns is not supported")));
}
else                    /* expression */
{
...
}

you didn't make sure the last "else" branch is not related to virtual
generated columns



pgsql-hackers by date:

Previous
From: Sutou Kouhei
Date:
Subject: Re: Make COPY format extendable: Extract COPY TO format implementations
Next
From: Sutou Kouhei
Date:
Subject: Re: Make COPY format extendable: Extract COPY TO format implementations