How slicing in Python works

The syntax is: a[start:stop] # items start through stop-1 a[start:] # items start through the rest of the array a[:stop] # items from the beginning through stop-1 a[:] # a copy of the whole array There is also the step value, which can be used with any of the above: a[start:stop:step] # start through not … Read more

How to choose between UUIDs, autoincrement/sequence keys and sequence tables for database primary keys?

UUIDs Unless these are generated “in increasing monotonic sequence” they can drastically hurt/fragment indexes. Support for UUID generation varies by system. While usable, I would not use a UUID as my primary clustered index/PK in most cases. If needed I would likely make it a secondary column, perhaps indexed, perhaps not. Some people argue that … Read more

Permutation algorithm without recursion? Java

You should use the fact that when you want all permutations of N numbers there are N! possibilities. Therefore each number x from 1..N! encodes such a permutation. Here is a sample that iteratively prints out all permutations of a sting. private static void printPermutationsIterative(String string){ int [] factorials = new int[string.length()+1]; factorials[0] = 1; … Read more

How to create an Oracle sequence starting with max value from a table?

If you can use PL/SQL, try (EDIT: Incorporates Neil’s xlnt suggestion to start at next higher value): SELECT ‘CREATE SEQUENCE transaction_sequence MINVALUE 0 START WITH ‘||MAX(trans_seq_no)+1||’ INCREMENT BY 1 CACHE 20′ INTO v_sql FROM transaction_log; EXECUTE IMMEDIATE v_sql; Another point to consider: By setting the CACHE parameter to 20, you run the risk of losing … Read more

PostgreSQL next value of the sequences?

RETURNING That’s possible with a single round-trip to the database: INSERT INTO tbl(filename) VALUES (‘my_filename’) RETURNING tbl_id; tbl_id would typically be a serial or IDENTITY (Postgres 10 or later) column. More in the manual. Explicitly fetch value If filename needs to include tbl_id (redundantly), you can still use a single query. Use lastval() or the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)