Skip to content

OPTIONAL MATCH with WHERE false returns no row when it is the first clause #2603

Open

Description

@YGY-001

Environment

  • Apache AGE: 1.8.0
  • PostgreSQL: 18.6
  • Docker image: apache/age:release_PG18_1.8.0
  • Access method: psql

Description

When a query starts with OPTIONAL MATCH and its attached WHERE predicate is
false, the query returns zero rows. I expected one row with null values for
the optional bindings.

Adding an explicit input row before OPTIONAL MATCH preserves that row and
returns null bindings, so the behavior appears specific to OPTIONAL MATCH
at the start of a query.

Reproduction

Environment setup:

LOAD 'age';
SET search_path = ag_catalog, public;
SELECT create_graph('test');

Create a matching edge:

SELECT * FROM cypher('test', $$
  CREATE (:A)-[:R]->(:B)
$$) AS (v agtype);

Run:

SELECT * FROM cypher('test', $$
  OPTIONAL MATCH (n)-[r:R]->()
  WHERE false
  RETURN startNode(r) AS s, endNode(r) AS e
$$) AS (s agtype, e agtype);

Actual result

The query succeeds but returns zero rows.

Expected result

The query returns one row with null values:

s    | e
null | null

Control

This query returns one row with null bindings:

SELECT * FROM cypher('test', $$
  WITH 1 AS seed
  OPTIONAL MATCH (n)-[r:R]->()
  WHERE false
  RETURN seed, n, r
$$) AS (seed agtype, n agtype, r agtype);

Activity

  1. Almaryj1 commented on Nov 13, 2026

    @Almaryj1

    Hi @jrgemignani @YGY-001 , I'd like to work on this. I'll add a regression test to document this OPTIONAL MATCH behaviour. Will submit a PR shortly.

  2. Almaryj1 commented on Nov 13, 2026

    @Almaryj1

    I've submitted a PR with regression tests documenting this OPTIONAL MATCH behavior: #2611. @jrgemignani would love your feedback when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions