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

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

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

MappedSuperclass – Change SequenceGenerator in Subclass

Yes, it is possible. You can override the default generator name with the @SequenceGenerator annotation. Base class @MappedSuperclass public abstract class PersistentEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = “default_gen”) protected Long id = 0L; public Long getId() { return id; } public void setId(Long id) … Read more

How to make a continuous alphabetic list python (from a-z then from aa, ab, ac etc)

Use itertools.product. from string import ascii_lowercase import itertools def iter_all_strings(): for size in itertools.count(1): for s in itertools.product(ascii_lowercase, repeat=size): yield “”.join(s) for s in iter_all_strings(): print(s) if s == ‘bb’: break Result: a b c d e … y z aa ab ac … ay az ba bb This has the added benefit of going … Read more

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