Hot answers tagged postgresql
I think you need something using ROW_NUMBER() and (integer) division by 2, along the lines of this: WITH p AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY supplier_id ORDER BY id)-1 AS rn FROM products ) SELECT * FROM p ORDER BY rn/2, supplier_id, rn ; Tested at SQLFiddle.
I have 3 solutions for you: Direct reference of sequence and using concat One possible solution is to reference the seqence in insert statement directly and prepend your node-id. A similar question including answer you can find here: http://stackoverflow.com/a/17925601/4206293 Using a UUID Another possible solution is, if you don't need you node-id in ...
Your query would fail, because the standard name of an integer is "integer", not "int". You can avoid this kind of error by comparing the internal regtype OID instead of a text representation. That aside, you can largely simplify and improve: SELECT a.attname , CASE a.atttypid WHEN 'bigint'::regtype THEN 'bigserial' WHEN ...
Only top voted, non community-wiki answers of a minimum length are eligible