duckdb 0.3.5-dev164.0 → 0.3.5-dev167.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.5-dev164.0",
4
+ "version": "0.3.5-dev167.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -51502,7 +51502,7 @@ void ART::VerifyExistence(DataChunk &chunk, VerifyExistenceType verify_type, str
51502
51502
  case VerifyExistenceType::APPEND_FK: {
51503
51503
  // found node no exists in tree
51504
51504
  exception_msg =
51505
- "violates foreign key constraint because key \"" + key_name + "\" no exist in referenced table";
51505
+ "violates foreign key constraint because key \"" + key_name + "\" does not exist in referenced table";
51506
51506
  break;
51507
51507
  }
51508
51508
  case VerifyExistenceType::DELETE_FK: {
@@ -148074,10 +148074,12 @@ unique_ptr<Constraint> Transformer::TransformConstraint(duckdb_libpgquery::PGLis
148074
148074
  for (auto kc = constraint->fk_attrs->head; kc; kc = kc->next) {
148075
148075
  fk_columns.emplace_back(reinterpret_cast<duckdb_libpgquery::PGValue *>(kc->data.ptr_value)->val.str);
148076
148076
  }
148077
- for (auto kc = constraint->pk_attrs->head; kc; kc = kc->next) {
148078
- pk_columns.emplace_back(reinterpret_cast<duckdb_libpgquery::PGValue *>(kc->data.ptr_value)->val.str);
148077
+ if (constraint->pk_attrs) {
148078
+ for (auto kc = constraint->pk_attrs->head; kc; kc = kc->next) {
148079
+ pk_columns.emplace_back(reinterpret_cast<duckdb_libpgquery::PGValue *>(kc->data.ptr_value)->val.str);
148080
+ }
148079
148081
  }
148080
- if (pk_columns.size() != fk_columns.size()) {
148082
+ if (!pk_columns.empty() && pk_columns.size() != fk_columns.size()) {
148081
148083
  throw ParserException("The number of referencing and referenced columns for foreign keys must be the same");
148082
148084
  }
148083
148085
  if (fk_columns.empty()) {
@@ -157087,6 +157089,7 @@ public:
157087
157089
 
157088
157090
 
157089
157091
 
157092
+
157090
157093
  namespace duckdb {
157091
157094
 
157092
157095
  SchemaCatalogEntry *Binder::BindSchema(CreateInfo &info) {
@@ -157211,6 +157214,35 @@ void Binder::BindLogicalType(ClientContext &context, LogicalType &type, const st
157211
157214
  }
157212
157215
  }
157213
157216
 
157217
+ static void FindMatchingPrimaryKeyColumns(vector<unique_ptr<Constraint>> &constraints, ForeignKeyConstraint &fk) {
157218
+ if (!fk.pk_columns.empty()) {
157219
+ return;
157220
+ }
157221
+ // find the matching primary key constraint
157222
+ for (auto &constr : constraints) {
157223
+ if (constr->type != ConstraintType::UNIQUE) {
157224
+ continue;
157225
+ }
157226
+ auto &unique = (UniqueConstraint &)*constr;
157227
+ if (!unique.is_primary_key) {
157228
+ continue;
157229
+ }
157230
+ idx_t column_count;
157231
+ if (unique.index != DConstants::INVALID_INDEX) {
157232
+ fk.info.pk_keys.push_back(unique.index);
157233
+ column_count = 1;
157234
+ } else {
157235
+ fk.pk_columns = unique.columns;
157236
+ column_count = unique.columns.size();
157237
+ }
157238
+ if (column_count != fk.fk_columns.size()) {
157239
+ throw BinderException("The number of referencing and referenced columns for foreign keys must be the same");
157240
+ }
157241
+ return;
157242
+ }
157243
+ throw BinderException("there is no primary key for referenced table \"%s\"", fk.info.table);
157244
+ }
157245
+
157214
157246
  BoundStatement Binder::Bind(CreateStatement &stmt) {
157215
157247
  BoundStatement result;
157216
157248
  result.names = {"Count"};
@@ -157291,13 +157323,15 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
157291
157323
  if (fk.info.type != ForeignKeyType::FK_TYPE_FOREIGN_KEY_TABLE) {
157292
157324
  continue;
157293
157325
  }
157294
- D_ASSERT(fk.info.pk_keys.empty() && !fk.pk_columns.empty());
157326
+ D_ASSERT(fk.info.pk_keys.empty());
157295
157327
  if (create_info.table == fk.info.table) {
157296
157328
  fk.info.type = ForeignKeyType::FK_TYPE_SELF_REFERENCE_TABLE;
157329
+ FindMatchingPrimaryKeyColumns(create_info.constraints, fk);
157297
157330
  } else {
157298
157331
  // have to resolve referenced table
157299
157332
  auto pk_table_entry_ptr = catalog.GetEntry<TableCatalogEntry>(context, fk.info.schema, fk.info.table);
157300
- D_ASSERT(!fk.pk_columns.empty() && fk.info.pk_keys.empty());
157333
+ D_ASSERT(fk.info.pk_keys.empty());
157334
+ FindMatchingPrimaryKeyColumns(pk_table_entry_ptr->constraints, fk);
157301
157335
  for (auto &keyname : fk.pk_columns) {
157302
157336
  auto entry = pk_table_entry_ptr->name_map.find(keyname);
157303
157337
  if (entry == pk_table_entry_ptr->name_map.end()) {