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

COPY...FROM stream doesn't work with interpolated values #532

Closed
partap opened this issue Dec 14, 2022 · 1 comment
Closed

COPY...FROM stream doesn't work with interpolated values #532

partap opened this issue Dec 14, 2022 · 1 comment

Comments

@partap
Copy link

partap commented Dec 14, 2022

I'm trying to import values using COPY FROM piped from a readable stream, but the sql helper only gives me errors.

The example from the docs works as written:

const userStream = Readable.from([
  'Murray\t68\n',
  'Walter\t80\n'
])
const query = await sql`copy test_table ( name, age ) from stdin`.writable()
await pipeline(userStream, query);

But, if I want to interpolate the table and/or column names, it doesn't work:

const tableName = 'test_table'
const cols = [ 'name', 'age' ]

// Interpolate both table name and columns
const query = await sql`copy ${sql(tableName)} (${sql(cols)}) from stdin`.writable()
// --> Error: Could not infer helper mode

// Only interpolate columns
const query = await sql`copy test_table (${sql(cols)}) from stdin`.writable()
// --> Error: Could not infer helper mode

// Only interpolate table name
const query = await sql`copy ${sql(tableName)} (name, age) from stdin`.writable()
// --> PostgresError: syntax error at end of input

There's a full (non) working example here: https://gist.github.com/partap/fefc18a0d294dae033c893f2d2828187

@porsager
Copy link
Owner

porsager commented Feb 1, 2023

Nice finds. Finally had a little time to fix that.

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