Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Can't listen to channel with uppercase letter in it #529

Open
skyqrose opened this issue Feb 9, 2025 · 0 comments
Open

bug: Can't listen to channel with uppercase letter in it #529

skyqrose opened this issue Feb 9, 2025 · 0 comments
Assignees

Comments

@skyqrose
Copy link

skyqrose commented Feb 9, 2025

pg.listen doesn't work if the channel name has an uppercase letter in it.

Test that reproduces this:

/**
 * @jest-environment node
 */
import { PGlite } from "@electric-sql/pglite";

test("can notify", async () => {
  const pg = await PGlite.create();
  const f1 = jest.fn(console.log);
  const f2 = jest.fn(console.log);
  await pg.listen("test1", f1);
  await pg.listen("tesT2", f2);
  await pg.query("NOTIFY test1, 'test1'");
  await pg.query("NOTIFY tesT2, 'tesT2'");
  expect(f1).toHaveBeenCalled(); // passes, "test1" is printed
  expect(f2).toHaveBeenCalled(); // fails, "tesT2" is NOT printed
});

I also tried it in plain Postgres (not PGlite) and it worked, so this is definitely a bug in PGlite. It's probably due to some interaction with Postgres's case insensitivity.

plain postgres example that works as expected
LISTEN test1;
LISTEN tesT2;
NOTIFY tesT2, 'tesT2';
NOTIFY test1, 'test1'; 

I ran into this because it makes live queries not work on tables with an uppercase letter in their name, because the table name is used in the channel name and live queries are implemented with .listen. The workaround is to not use uppercase letters in your table name.

I haven't personally tested anything but a small portion of ASCII, but obviously anything that's a valid identifier should work. Here's Postgres's docs for valid characters in identifiers.

PGlite version 0.2.15

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

No branches or pull requests

2 participants