PostgreSQL ORDER BY issue – natural sort

Since Postgres 9.6, it is possible to specify a collation which will sort columns with numbers naturally. https://www.postgresql.org/docs/10/collation.html — First create a collation with numeric sorting CREATE COLLATION numeric (provider = icu, locale=”en@colNumeric=yes”); — Alter table to use the collation ALTER TABLE “employees” ALTER COLUMN “em_code” type TEXT COLLATE numeric; Now just query as you … Read more

TSQL – Is it possible to define the sort order?

It’s incredibly clunky, but you can use a CASE statement for ordering: SELECT * FROM Blah ORDER BY CASE MyColumn WHEN ‘orange’ THEN 1 WHEN ‘apple’ THEN 2 WHEN ‘strawberry’ THEN 3 END Alternately, you can create a secondary table which contains the sort field and a sort order. TargetValue SortOrder orange 1 apple 2 … Read more

Using Spring JdbcTemplate to extract one string

It would help a lot to know what your SQL query looks like, but assuming it’s something like SELECT STREET_NAME FROM table WHERE ID=1; CODE: public String getStreetNameById(int id) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = “SELECT STREET_NAME FROM table WHERE ID=?”; String streetName = (String) jdbcTemplate.queryForObject( sql, new Object[] { id }, … Read more

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