Skip to content

Syntax error in SQL #2

Open
Open

Description

@oojacoboo

ERROR: syntax error at or near "." at character 115
STATEMENT: CREATE OR REPLACE FUNCTION null_count(
argument json
) RETURNS int LANGUAGE sql IMMUTABLE AS 'SELECT @extschema@.null_count($1::jsonb)';
psql:/docker-entrypoint-initdb.d/count_nulls.sql:19: ERROR: syntax error at or near "."
LINE 3: ... int LANGUAGE sql IMMUTABLE AS 'SELECT @extschema@.null_coun..

Activity

  1. jnasbyupgrade commented on Sep 29, 2026

    @jnasbyupgrade
    Contributor

    This still reproduces on current master (b52d136), PostgreSQL 17, but only when sql/count_nulls.sql is executed directly (e.g. psql -f sql/count_nulls.sql, or dropping it into /docker-entrypoint-initdb.d/) rather than installed with CREATE EXTENSION count_nulls.

    $ psql -d issue2_test -f sql/count_nulls.sql
    psql:sql/count_nulls.sql:17: ERROR:  syntax error at or near "."
    LINE 3: ... int LANGUAGE sql IMMUTABLE AS 'SELECT @extschema@.null_coun...
    psql:sql/count_nulls.sql:41: ERROR:  syntax error at or near "."
    LINE 17:   IF @extschema@.null_count( row_to_json(NEW) ) <> TG_ARGV[0...
    psql:sql/count_nulls.sql:60: ERROR:  syntax error at or near "."
    psql:sql/count_nulls.sql:84: ERROR:  syntax error at or near "."
    

    Cause: @extschema@ is a placeholder that PostgreSQL substitutes only while CREATE EXTENSION runs an extension script. Any other way of loading the file leaves the literal @extschema@ in the SQL, and the parser rejects it at the following .. That affects null_count(json), not_null_count(json), and the bodies of the two trigger functions.

    Nothing in the history has changed this. The repo's own test suite always installs via CREATE EXTENSION, so it doesn't exercise the direct-load path.

    Workaround: install with make install and then CREATE EXTENSION count_nulls; (in Docker, run that from an init script instead of loading the .sql file).

    Open question for a fix: either document that the sql/*.sql files are extension scripts and not standalone scripts, or make a direct load fail with a clearer message.

    🤖 Generated with Claude Code

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions