Vercel's Postgres won't do one-to-many join (cartesian product)?

I am able to connect and use Vercel’s Postgres storage addon, but encountered a bug that I can’t reproduce in normal Postgres. I have two tables with a one-to-many relationship. When I join the two tables, I expect a cartesian product – one row for each of the many relationships. However, I only get one row back!

Here’s my schema code:

DROP TABLE IF EXISTS LinksA CASCADE;
DROP TABLE IF EXISTS LinkContentsA CASCADE;

CREATE TABLE IF NOT EXISTS LinksA (id BIGSERIAL PRIMARY KEY, url TEXT);
CREATE TABLE IF NOT EXISTS LinkContentsA (
  link_id BIGINT NOT NULL REFERENCES LinksA(id),
  link_content TEXT NOT NULL
);


INSERT INTO LinksA (url) VALUES ('https://a.com');
INSERT INTO LinksA (url) VALUES ('https://b.com');
INSERT INTO LinkContentsA (link_id, link_content) VALUES (1, 'hello');
INSERT INTO LinkContentsA (link_id, link_content) VALUES (1, 'goodbye');
INSERT INTO LinkContentsA (link_id, link_content) VALUES (1, 'foo');
INSERT INTO LinkContentsA (link_id, link_content) VALUES (1, 'bar');

Here’s my query:

SELECT * FROM LinksA
JOIN LinkContentsA ON LinkContentsA.link_id = LinksA.id

DB Fiddle - SQL Database Playground clearly shows 4 rows (expected) but running the same thing in Vercel’s DB web UI only returns 1 row. As far as I can tell, this bug seems specific to Vercel, but it seems like such a glaring bug.

Hi there, are you able to reproduce this when running your query against the database directly (i.e. with psql or some other client)?

I tested your schema and query with EXPLAIN ANALYZE - the query plan is the same in both the web UI as well as the direct query, the latter of which did return the expected results. Seems like this is a UI bug rather than an issue with the database service. Let me know if you don’t think this is the case, but either way I’ll make sure the appropriate team sees this. Thanks for flagging!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.