Skip to content

Fix Makefile PG version check breaking on pre-release versions#32

Open
maqeel75 wants to merge 1 commit into
mainfrom
fix/makefile-pg-version-parse-prerelease
Open

Fix Makefile PG version check breaking on pre-release versions#32
maqeel75 wants to merge 1 commit into
mainfrom
fix/makefile-pg-version-parse-prerelease

Conversation

@maqeel75

@maqeel75 maqeel75 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Problem

The check-pg-version target derives pg_version_num with a regex that requires a MAJOR.MINOR dotted format:

pg_version_num := $(shell $(PG_CONFIG) --version | sed 's/^PostgreSQL *//' | \
	sed 's/\([0-9]*\)\.\([0-9]*\).*/\1\2/')

PostgreSQL pre-release builds report a version like 19beta1no dot — so the substitution does not match and the full descriptive string is left in place.

On Debian/Ubuntu, pg_config --version also appends a distro suffix, e.g.:

PostgreSQL 19beta1 (Ubuntu 19~beta1-1.noble)

The unmatched string then flows into the shell test as:

if [ 19beta1 (Ubuntu 19~beta1-1.noble) -lt 14 ]; then

which fails under dash (/bin/sh on Debian/Ubuntu):

/bin/sh: 1: Syntax error: "(" unexpected (expecting "then")
make[1]: *** [Makefile:67: check-pg-version] Error 2

This breaks the PostgreSQL 19 .deb build. RPM builds happened to survive only because the RHEL version string has no parenthetical suffix (PostgreSQL 19beta1), so the numeric test quietly no-op'd and the if fell through.

Note the extension's C sources compile cleanly against PG19 on both platforms — this is purely a version-check parsing bug.

Fix

Parse just the leading major-version integer and quote the value in the test, so it is robust for both pre-release and stable versions under dash and bash:

pg_version_num := $(shell $(PG_CONFIG) --version | sed -E 's/^PostgreSQL ([0-9]+).*/\1/')
...
	@if [ "$(pg_version_num)" -lt 14 ]; then

Verification

Parsed major + [ … -lt 14 ] under dash for each real version string:

pg_config --version parsed result
PostgreSQL 19beta1 (Ubuntu 19~beta1-1.noble) 19 OK
PostgreSQL 19beta1 19 OK
PostgreSQL 17.6 17 OK
PostgreSQL 14.12 (Debian 14.12-1) 14 OK
PostgreSQL 13.2 13 correctly rejected

The check-pg-version target derived pg_version_num with a regex that
required a MAJOR.MINOR dotted format. PostgreSQL pre-release builds
report a version like "19beta1" with no dot, so the substitution did
not match and left the full descriptive string in place.

On Debian/Ubuntu, pg_config --version also appends a distro suffix,
e.g. "PostgreSQL 19beta1 (Ubuntu 19~beta1-1.noble)". The unmatched
string then flowed into the shell test as:

    if [ 19beta1 (Ubuntu 19~beta1-1.noble) -lt 14 ]; then

which fails under dash (/bin/sh on Debian/Ubuntu) with:

    /bin/sh: 1: Syntax error: "(" unexpected (expecting "then")

breaking the PG19 .deb build. (RPM builds happened to survive only
because their version string has no parenthetical suffix.)

Parse just the leading major-version integer and quote the value in
the test so it is robust for both pre-release and stable versions on
dash and bash.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Makefile's PostgreSQL version compatibility check was modified to extract only the leading major version number from pg_config --version output using a regex, replacing the previous approach that stripped the "PostgreSQL" prefix and concatenated major/minor version numbers. The change tolerates pre-release version strings. The existing minimum version guard (PostgreSQL 14+) continues to use the resulting pg_version_num value unchanged.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the Makefile PostgreSQL version-check fix for pre-release versions.
Description check ✅ Passed The description directly matches the changeset and explains the version-parsing fix in detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/makefile-pg-version-parse-prerelease

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Makefile (1)

66-76: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

LGTM — regex correctly isolates the major version for pre-release strings.

The anchored sed -E 's/^PostgreSQL ([0-9]+).*/\1/' properly extracts just the leading integer from strings like PostgreSQL 19beta1 (Ubuntu 19~beta1-1.noble), and quoting "$(pg_version_num)" in the -lt test avoids the dash word-splitting failure described in the PR. This matches the documented pg_config --version output format (PostgreSQL MAJOR.MINOR or pre-release variants).

One minor defensive note: if pg_config --version output ever lacks the literal PostgreSQL prefix (unexpected but not impossible across future toolchains/packagers), the anchored substitution silently no-ops and pg_version_num becomes non-numeric, causing the shell -lt test to fail with a generic "integer expression expected" error instead of the intended message. Not a blocker given the current well-established output format.

web_search: pg_config --version output format Confirmed the standard output format is "The output displays the “14.6” version of PostgreSQL that is currently installed in Ubuntu.", i.e., prefixed with "PostgreSQL".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 66 - 76, Add defensive validation to handle edge cases
where the pg_config --version output lacks the expected PostgreSQL prefix and
the pg_version_num variable fails to extract a valid numeric value. Modify the
check-pg-version target to validate that pg_version_num contains a numeric value
before performing the -lt comparison, and provide a clear error message (e.g.,
indicating that pg_config output format is unexpected) if validation fails,
rather than allowing the generic "integer expression expected" error to surface
to users.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Makefile`:
- Around line 66-76: Add defensive validation to handle edge cases where the
pg_config --version output lacks the expected PostgreSQL prefix and the
pg_version_num variable fails to extract a valid numeric value. Modify the
check-pg-version target to validate that pg_version_num contains a numeric value
before performing the -lt comparison, and provide a clear error message (e.g.,
indicating that pg_config output format is unexpected) if validation fails,
rather than allowing the generic "integer expression expected" error to surface
to users.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e913c619-59db-4738-8d88-b61cbf997f14

📥 Commits

Reviewing files that changed from the base of the PR and between 904babc and 92f765c.

📒 Files selected for processing (1)
  • Makefile

@maqeel75 maqeel75 requested a review from dpage July 9, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant