Skip to content

fix(postgres): Handle case-sensitive column names#57

Merged
julien040 merged 1 commit intojulien040:mainfrom
david-pivonka:fix/postgres-case-sensitive-columns
Sep 30, 2025
Merged

fix(postgres): Handle case-sensitive column names#57
julien040 merged 1 commit intojulien040:mainfrom
david-pivonka:fix/postgres-case-sensitive-columns

Conversation

@david-pivonka
Copy link
Copy Markdown
Contributor

This PR fixes an issue where camelCased column names in PostgreSQL were not being handled correctly, leading to query errors.

@julien040 julien040 self-assigned this Aug 16, 2025
@julien040 julien040 added the bug Something isn't working label Aug 16, 2025
Repository owner deleted a comment from vercel bot Aug 16, 2025
@julien040
Copy link
Copy Markdown
Owner

julien040 commented Aug 16, 2025

Hello @david-pivonka,
Thank you for opening this pull request!

Can you detail what kind of issues you were encountering? I tried to reproduce the issue on my computer, but I couldn't. The query worked with and without the patch.

-- Run on PostgreSQL
CREATE TABLE a (
	id VARCHAR PRIMARY KEY,
	myAge INTEGER,
	myName VARCHAR
);

-- Run on Anyquery
SELECT * FROM a

Or is it with a table that has two columns, with one camel-cased? Because SQLite (which Anyquery is based on) converts both to mycol, and it fails.

CREATE TABLE test (
    mycol INT,
    "MyCol" INT
);

Anyway, I'm still going to merge this pull request because Anyquery should always pass the escaped identifier to the end database. I'm just curious.

@julien040 julien040 merged commit 02a3f6e into julien040:main Sep 30, 2025
2 checks passed
rickalee added a commit to rickalee/anyquery that referenced this pull request Nov 6, 2025
…words

Fixes issue where MySQL tables with reserved keyword columns (e.g., `order`)
cannot be queried due to missing backtick escaping in generated SQL.

Changes:
- Add flavor parameter to constructSQLQuery() and efficientConstructSQLQuery()
- Use flavor.Quote() to properly escape column names based on database type
- MySQL uses backticks (`column`), PostgreSQL uses double quotes ("column")
- Apply escaping to both SELECT columns and ORDER BY clauses

Impact:
- Enables querying WordPress Content Connect tables (wp_post_to_post)
- Fixes queries on any MySQL table with reserved keyword columns
- Similar to PR julien040#57 which fixed PostgreSQL column name handling

Tested:
- Successfully queried wp_post_to_post table with 'order' column
- Verified COUNT, SELECT, and aggregation queries work correctly
- Tested with 284,909 relationship records

Example working query:
  SELECT id1, id2, name FROM msresearch.wp_post_to_post LIMIT 5

Previously failed with:
  Error 1064: syntax error near 'order FROM `local`.`wp_post_to_post`'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants