Store same sequence value in two columns
In order to not rely at all on currval, you might transform the INSERT queries in systematic way following this pattern:


To insert from a select, instead of :

INSERT INTO Test(columns) SELECT columns FROM...;

consider this form:

INSERT INTO Test(test_id, uid, columns) 
SELECT pk,pk,columns FROM
(SELECT nextval('test_id_seq') as pk, columns FROM ...) AS alias;

For a single row in a VALUES clause, instead of

INSERT INTO Test(columns) VALUES(...values here...)


consider:

INSERT INTO Test(test_id, uid, columns...) 
SELECT pk,pk,columns FROM
 (SELECT nextval('test_id_seq') as pk, ...values here...) AS alias;

for VALUES clauses with multiple rows, instead of:

INSERT INTO Test(columns) VALUES(...values1...),(...values2...)


consider:

 WITH v(columns...) AS ( VALUES(...values1...),(...values2...) )
 INSERT INTO Test(test_id, uid, columns) 
 SELECT pk,pk,columns... FROM
  (SELECT nextval('test_id_seq') as pk, v.columns... FROM v) AS alias;





If PostgreSQL had a standard-compliant NEXTVAL, you could do without the subquery and just use something like:

INSERT INTO ... SELECT NEXT VALUE FOR seqname,
                       NEXT VALUE FOR seqname,
                       other columns...


and the NEXT VALUE FOR seqname would evaluate to the same value for both columns of the same output row, as mandated by the standard. But PostgreSQL does not have this construct.