Search Postgresql Archives

Re: Merging records in a table with 2-columns primary key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Andy and others -

On Sun, Apr 2, 2017 at 5:13 PM, Andy Colson <andy@xxxxxxxxxxxxxxx> wrote:


after some thinking, when I call

SELECT out_uid FROM merge_users(ARRAY[1,2,3,4]);

then "reviews" table should be empty (get rid of all self-reviews)
and "users" should contain just 1 record (1, 'User 1').

And if instead I call 

SELECT out_uid FROM merge_users(ARRAY[1,2]);

then "reviews" should be (records with User 2 removed because overlapped with User 1):

 uid | author |         review         
-----+--------+------------------------
   1 |      3 | User 3 says: 1 is nice
   1 |      4 | User 4 says: 1 is nice
   3 |      1 | User 1 says: 3 is nice
   3 |      4 | User 4 says: 3 is ugly
   4 |      1 | User 1 says: 4 is ugly
   4 |      3 | User 3 says: 4 is ugly

and "users":

 uid |  name  
-----+--------
   1 | User 1
   3 | User 3
   4 | User 4

So my 2 questions are -

1) Why the error when calling merge_users(ARRAY[1,2]) and then merge_users(ARRAY[1,2,3,4])?

2) Is there a way to use an UPDATE reviews instead of the inefficient (because copying) INSERT ... SELECT ... ON CONFLICT DO NOTHING?

Thank you
Alex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux