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

Creating a unique sequence of dates

As I noted in my comment, seq has method for dates, seq.Date: seq(as.Date(‘2011-01-01’),as.Date(‘2011-01-31’),by = 1) [1] “2011-01-01” “2011-01-02” “2011-01-03” “2011-01-04” “2011-01-05” “2011-01-06” “2011-01-07” “2011-01-08” [9] “2011-01-09” “2011-01-10” “2011-01-11” “2011-01-12” “2011-01-13” “2011-01-14” “2011-01-15” “2011-01-16” [17] “2011-01-17” “2011-01-18” “2011-01-19” “2011-01-20” “2011-01-21” “2011-01-22” “2011-01-23” “2011-01-24” [25] “2011-01-25” “2011-01-26” “2011-01-27” “2011-01-28” “2011-01-29” “2011-01-30” “2011-01-31”

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

SQL Server 2005 – using generated sequences instead of Identity columns?

Yes, SQL 11 has SEQUENCE objects, see SQL Server v.Next (Denali) : Using SEQUENCE. Creating manual sequences is possible, but not recommended. The trick to do a sequence generator is to use UPDATE WITH OUTPUT on a sequences table. Here is pseudo-code: CREATE TABLE Sequences ( Name sysname not null primary key, Sequence bigint not … Read more