Is it possible to reference an inserted column within the same INSERT?
This query gives the error:
create table qwe (a bigint, completed bit varying(100000)); CREATE TABLE
insert into qwe (a, completed) values (1000, repeat('0', a));
ERROR: column "a" does not exist
You probably also saw the hint:
HINT: There is a column named "a" in table "qwe", but it cannot be referenced from this part of the query.
You cannot reference a column value that does not exist, yet.
Instead, spell out the value again. Or use a subselect or CTE to provide
INSERT INTO qwe (a, completed) VALUES (1000, repeat('0', 1000)::varbit);
INSERT INTO qwe (a, completed)
SELECT a, repeat('0', a)::varbit
FROM (SELECT 1000) sub(a);
Also, you need an explicit cast to