Postgresql enforce unique two-way combination of columns

A variation on Neil’s solution which doesn’t need an extension is: create table friendz ( from_id int, to_id int ); create unique index ifriendz on friendz(greatest(from_id,to_id), least(from_id,to_id)); Neil’s solution lets you use an arbitrary number of columns though. We’re both relying on using expressions to build the index which is documented https://www.postgresql.org/docs/current/indexes-expressional.html

How to select only the first rows for each unique value of a column?

A very simple answer if you say you don’t care which address is used. SELECT CName, MIN(AddressLine) FROM MyTable GROUP BY CName If you want the first according to, say, an “inserted” column then it’s a different query SELECT M.CName, M.AddressLine, FROM ( SELECT CName, MIN(Inserted) AS First FROM MyTable GROUP BY CName ) foo … Read more

Does a name attribute have to be unique in a HTML document?

The name attribute is only valid on the <form> and form elements (<input>,<textarea> and <select>). It’s used to specify the name to associate with the name/value pair that is submitted on a form post. For example: <input type=”checkbox” name=”foo” value=”1″ /> if checked will submit foo=1. In the DOM you can reference form elements from … Read more

Merge two numerically-keyed associative arrays and preserve the original keys

Just use: $output = array_merge($array1, $array2); That should solve it. Because you use string keys if one key occurs more than one time (like ’44’ in your example) one key will overwrite preceding ones with the same name. Because in your case they both have the same value anyway it doesn’t matter and it will … Read more

Detecting a “unique” anonymous user

There are actually many ways you can detect a “unique” user. Many of these methods are used by our marketing friends. It get’s even easier when you have plugins enabled such as Java, Flash etc. Currently my favorite presentation of cookie based tracking is evercookie (http://samy.pl/evercookie/). It creates a “permanent” cookie via multiple storage mechanisms, … Read more

tech