java.lang.ClassNotFoundException: org.postgresql.Driver, Android

You need to add the PostgreSQL JDBC Driver in your project as mentioned in Gradle: implementation ‘org.postgresql:postgresql:42.2.10’ Maven: <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.2.10</version> </dependency> You can also download the JAR and import to your project manually. NOTE: Compile as used in this answer is deprecated. Replace with implementation as per 3.

PostgreSQL ORDER BY issue – natural sort

Since Postgres 9.6, it is possible to specify a collation which will sort columns with numbers naturally. — 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

Using pyspark to connect to PostgreSQL

Download the PostgreSQL JDBC Driver from Then replace the database configuration values by yours. from pyspark.sql import SparkSession spark = SparkSession \ .builder \ .appName(“Python Spark SQL basic example”) \ .config(“spark.jars”, “/path_to_postgresDriver/postgresql-42.2.5.jar”) \ .getOrCreate() df = \ .format(“jdbc”) \ .option(“url”, “jdbc:postgresql://localhost:5432/databasename”) \ .option(“dbtable”, “tablename”) \ .option(“user”, “username”) \ .option(“password”, “password”) \ .option(“driver”, “org.postgresql.Driver”) … Read more

Oracle equivalent of Postgres’ DISTINCT ON?

The same effect can be replicated in Oracle either by using the first_value() function or by using one of the rank() or row_number() functions. Both variants also work in Postgres. first_value() select distinct col1, first_value(col2) over (partition by col1 order by col2 asc) from tmp first_value gives the first value for the partition, but repeats … Read more

Prevent recursive trigger in PostgreSQL

This is what I do in PostgreSQL 9.2, although I must admit I did not find this approach documented. There is a function pg_trigger_depth() documented here, which I use to differentiate between original and nested calls in the trigger. CREATE TRIGGER trg_taxonomic_positions AFTER INSERT OR UPDATE OF taxonomic_position ON taxon_concepts FOR EACH ROW WHEN (pg_trigger_depth() … Read more