skip to Main Content

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?

2

Answers


  1. This is yours:

    Select *, md5(array_to_string(translate(string_to_array(f::text, ',')::text, '()', '')::text[], '')) from my_table as f;
    
    Login or Signup to reply.
  2. 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));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search