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

Allow to specify or exclude insert columns #218

Merged
merged 5 commits into from
Jan 12, 2024

Conversation

slvrtrn
Copy link
Contributor

@slvrtrn slvrtrn commented Dec 23, 2023

Summary

It is now possible to either specify a list of columns to insert the data into or a list of excluded columns:

// Generated query: INSERT INTO mytable (message) FORMAT JSONEachRow
await client.insert({
  table: 'mytable',
  format: 'JSONEachRow',
  values: [{ message: 'foo' }],
  columns: ['message'],
})

// Generated query: INSERT INTO mytable (* EXCEPT (message)) FORMAT JSONEachRow
await client.insert({
  table: 'mytable',
  format: 'JSONEachRow',
  values: [{ id: 42 }],
  columns: { exclude: ['message'] },
})

Added more examples:

Resolves #217

NB: the EXCEPT clause works with ephemeral types rather strangely (see the tests). It is also possible to exclude every single column via HTTP + streams, and the query does not fail, though the data is not inserted - I couldn't simulate that via CLI as it does not allow empty values. It is also possible to exclude a column that does not exist (same in the CLI). All of this is to be investigated.

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • Website docs update

@slvrtrn slvrtrn merged commit aafc649 into main Jan 12, 2024
23 checks passed
@slvrtrn slvrtrn deleted the allow-to-specify-insert-columns branch January 12, 2024 10:55
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.

Allow to specify a list of columns for insert
2 participants