pdo-database-class icon indicating copy to clipboard operation
pdo-database-class copied to clipboard

Support for CrateDB

Open amotl opened this issue 11 months ago • 2 comments

Dear Vasiliy. Dear PDOdb community.

Just wow: Your PDOdb library looks truly excellent. Kudos for conceiving it. We discovered it ~~accidentally~~ by fortune while researching solutions for PostgreSQL query caching, so we can't resist to leave you this note.

Our background is that we don't actively do much PHP today, so please forgive us our ignorance about not knowing PDOdb, but we are still trying to maintain CrateDB's PDO and DBAL drivers irregularily. The thing is that both drivers have been conceived in the infancy of CrateDB, when it was only able to speak HTTP.

Because CrateDB also talks PostgreSQL today for standardization purposes, we are thinking about gradually detouring from those adapters, see also https://github.com/crate/crate-dbal/issues/107. In this spirit, we think PDOdb could be great for users of CrateDB, and adding support could be relatively easy because I see the architecture of PDOdb is already supporting multiple dialects? 💯

With kind regards, Andreas.

NB: Feel free to close this issue at your disposal, because it is actually a non-issue, but merely a proposal to get in touch with you to ask if you like the idea to add CrateDB support, and if you would welcome a corresponding contribution.

amotl avatar Dec 08 '25 21:12 amotl

Dear Andreas,

Thank you very much for your kind words and for taking the time to reach out — I truly appreciate your interest in PDOdb. I’m glad you came across PDOdb while exploring PostgreSQL query caching solutions.

Regarding CrateDB support: your idea is very interesting. I will take a closer look at its PostgreSQL wire protocol compatibility and the specific SQL features PDOdb relies on. If compatibility is sufficient, adding a dedicated CrateDB dialect should be straightforward given PDOdb’s architecture.

I’ll start looking into this and will keep you updated. In the meantime, feel free to share any specific resources or compatibility notes from your side.

With kind regards, Vasiliy.

tommyknocker avatar Dec 09 '25 01:12 tommyknocker

Hi Vasiliy,

thank you for your swift reply. While we don't have a database adapter authoring guide about the most prominent specialities of CrateDB, I can try to enumerate some of them briefly.

  • CrateDB is an analytical database (OLAP), so it doesn't provide transactions (OLTP). This means BEGIN and COMMIT should be made no-ops, and ROLLBACK should raise an exception. If your framework implements the notion of transaction isolation levels, READ_UNCOMMITTED would be the appropriate one.
  • Because of CrateDB's eventual consistency, clients may need to emit "REFRESH TABLE <tablename>" statements to synchronize writes where and when appropriate. The default automatic synchronization interval is 1 second. In CrateDB jargon, this is called refreshing. See also REFRESH and refresh_interval.
  • Because CrateDB is a fully distributed database, it doesn't provide any means for generating autoincrement primary keys, i.e. doesn't implement sequences like PostgreSQL. That's indeed a real bummer for traditional ActiveRecord or ORM frameworks, specifically if they absolutely rely on that. As a workaround, users or frameworks can use the current timestamp (now()), or random identifiers (gen_random_text_uuid()). This means the DDL generation routines will need to accompany a few adjustments in this regard, compared to standard PostgreSQL.
  • While CrateDB is a distributed database, it DOES support JOIN operations. However, it does not support FOREIGN KEY constraints, so those would need to be omitted from DDL clauses.
  • About type support, the most prominent deviance is that CrateDB does not support storing TIME and DATE types. As a workaround, they need to be mapped to TIMESTAMP instead. Other than this, after recently adding DECIMAL(), CrateDB offers a good share of the most common types in PostgreSQL, but a few more others.
  • The other most prominent deviance in type support is container types: CrateDB's OBJECT(DYNAMIC) is the type that is most closest to PostgreSQL's JSON type, and CrateDB also provides ARRAY.
  • About other special features, CrateDB has you covered, but its implementations are different than PostgreSQL's. Because it's all SQL, mostly that would need to be changed.
    • FTS: CrateDB does not support PostgreSQL's fulltext indexes like Gin, but implements them on top of Lucene, so querying is different, see MATCH.
    • Geospatial types: CrateDB is not PostGIS compatible, its geospatial functions and data types are different, but based on GeoJSON standards. See also geo search.
    • Vector store: CrateDB provides a FLOAT_VECTOR data type with HNSW querying capabilities. It is different than pgvector again, but we have been able to adjust corresponding database adapters for pgvector successfully. See also vector search.

The easiest way to invoke a single-node instance of CrateDB for testing purposes is to use Docker or Podman.

docker run --rm -it --name=cratedb \
  --publish=4200:4200 --publish=5432:5432 \
  --env=CRATE_HEAP_SIZE=2g \
  docker.io/crate/crate:nightly '-Cdiscovery.type=single-node'

If you think the specialities of CrateDB disqualify support in PDOdb, due to the one or the other obstacle, please feel free to reject our idea any time.

With kind regards, Andreas.

NB: @surister, @matriv, @seut: Please proof-read my statements above and enhance/correct them where needed / add items I might have forgotten. 🙏

amotl avatar Dec 09 '25 03:12 amotl