Home > front end >  Insert hash value of a row as new column in Postgres
Insert hash value of a row as new column in Postgres

Time:10-22

I have this query in Postgres that returns a hash value for every row of my table:

  SELECT
  md5(CAST((f.*)AS text))
  FROM
  my_table f;

I want to attach each hash to its corresponding row. How would I take the results for each row and add them to a new column?

CodePudding user response:

It is easy to do. Whether it is a good idea is a another matter.

alter table my_table add hash_col text;
update my_table set hash_col =md5(cast((my_table.*) as text));

CodePudding user response:

This is yours:

Select *, md5(array_to_string(translate(string_to_array(f::text, ',')::text, '()', '')::text[], '')) from my_table as f;
  • Related