Skip to content

Instantly share code, notes, and snippets.

@amotl
Created March 31, 2026 07:20
Show Gist options
  • Select an option

  • Save amotl/f50254ee6baa6d27cf45b8ceffea88a1 to your computer and use it in GitHub Desktop.

Select an option

Save amotl/f50254ee6baa6d27cf45b8ceffea88a1 to your computer and use it in GitHub Desktop.
Recipe to reproduce `UnsupportedFeatureException[Function FunctionName{schema='null', name='count'}(text) is not a scalar function.]`
import sqlalchemy as sa
def workload():
"""
Install
uv pip install sqlalchemy-cratedb psycopg2-binary
Invoke
python cratedb_functionname_nested.py
Problem
UnsupportedFeatureException[Function FunctionName{schema='null', name='count'}(text) is not a scalar function.]
[SQL:
SELECT *
FROM parent
JOIN
(SELECT child.name AS name
FROM child
GROUP BY child.name
HAVING count(?) = ?) AS anon_1 ON parent.name = anon_1.name
]
[parameters: ('parent.name', '42')]
"""
# Works with PostgreSQL.
# docker run --rm --publish=5433:5432 --env "POSTGRES_HOST_AUTH_METHOD=trust" postgres:18 postgres -c log_statement=all
# engine = sa.create_engine("postgresql://postgres@localhost:5433")
# Fails with CrateDB.
# docker run --rm --publish=4200:4200 --publish=5432:5432 crate/crate:nightly -Cdiscovery.type=single-node
engine = sa.create_engine("crate://")
with engine.connect() as conn:
conn.execute(
sa.text("""
CREATE TABLE IF NOT EXISTS "parent" (
"name" TEXT NOT NULL,
"description" TEXT,
PRIMARY KEY ("name")
);
""")
)
conn.execute(
sa.text("""
CREATE TABLE IF NOT EXISTS "child" (
"name" TEXT NOT NULL,
PRIMARY KEY ("name")
);
""")
)
conn.execute(
sa.text("""
SELECT *
FROM parent
JOIN
(SELECT child.name AS name
FROM child
GROUP BY child.name
HAVING count(:name) = :value) AS anon_1 ON parent.name = anon_1.name
"""),
{"name": "parent.name", "value": "42"},
)
if __name__ == "__main__":
workload()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment