Monday, December 12, 2022

postgreSQL: how to copy (duplicate) a row with binary data

 

>PROBLEM

You need to duplicate a table's row copying from a previous one that contains decode binary data that we shal avoid using copy/paste.


>SOLUTION

Notice that in this example, prtkey and pubkey are binary fields using bytea type.

The uptime is a timestamptz not null field.

 

INSERT INTO keysvc (id,title,pvtkey,pubkey,status,uptime) VALUES( 2, 'ramnode4',null ,null ,1, CURRENT_TIMESTAMP);  

with keys as (SELECT pvtkey, pubkey, uptime FROM keysvc where id = 1)
update keysvc set pvtkey=(select pvtkey from keys), pubkey=(select pubkey from keys), uptime=(select uptime from keys) where id =40;

NOTE: this solution was also published by myself at this date on 
There you'll find another alternative.

>ENV

PostgreSQL


No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...