Repository: duckdb/duckdb
File: src/common/adbc/adbc.cpp (C++)

Code before:
	case IngestionMode::CREATE: {
		// CREATE mode: Create table, error if already exists
		auto sql = BuildCreateTableSQL(effective_catalog, effective_schema, table_name, types, names, false, temporary);
		duckdb_result result;
		if (duckdb_query(connection, sql.c_str(), &result) == DuckDBError) {
			const char *error_msg = duckdb_result_error(&result);
			// Check if error is about table already existing before destroying result
			bool already_exists = error_msg && std::string(error_msg).find("already exists") != std::string::npos;
			duckdb_destroy_result(&result);
			if (already_exists) {
				return ADBC_STATUS_ALREADY_EXISTS;
			}
			return ADBC_STATUS_INTERNAL;
		}
		duckdb_destroy_result(&result);
		break;
	}
	case IngestionMode::APPEND:
		// APPEND mode: No pre-check needed
		// The appender will naturally fail if the table doesn't exist
		break;
	case IngestionMode::REPLACE: {
		// REPLACE mode: Drop table if exists, then create
		auto drop_sql = BuildDropTableSQL(effective_catalog, effective_schema, table_name);
		auto create_sql =
		    BuildCreateTableSQL(effective_catalog, effective_schema, table_name, types, names, false, temporary);
		duckdb_result result;
		if (duckdb_query(connection, drop_sql.c_str(), &result) == DuckDBError) {
			SetError(error, duckdb_result_error(&result));
			duckdb_destroy_result(&result);
			return ADBC_STATUS_INTERNAL;
		}
		duckdb_destroy_result(&result);
		if (duckdb_query(connection, create_sql.c_str(), &result) == DuckDBError) {
			SetError(error, duckdb_result_error(&result));
			duckdb_destroy_result(&result);
			return ADBC_STATUS_INTERNAL;
		}
		duckdb_destroy_result(&result);
		break;
	}
	case IngestionMode::CREATE_APPEND: {
		// CREATE_APPEND mode: Create if not exists, append if exists
		auto sql = BuildCreateTableSQL(effective_catalog, effective_schema, table_name, types, names, true, temporary);
		duckdb_result result;
		if (duckdb_query(connection, sql.c_str(), &result) == DuckDBError) {
			SetError(error, duckdb_result_error(&result));
			duckdb_destroy_result(&result);
			return ADBC_STATUS_INTERNAL;
		}
		duckdb_destroy_result(&result);

Review comment (suggestion):
There appears to be a [`CREATE OR REPLACE`](https://duckdb.org/docs/stable/sql/statements/create_table#create-or-replace) statement. Or does it not work for temporary tables? (Also it doesn't necessarily have to be changed in this PR.)

Code after:
				return ADBC_STATUS_ALREADY_EXISTS;
			}
			return ADBC_STATUS_INTERNAL;
		}
		duckdb_destroy_result(&result);
		break;
	}
	case IngestionMode::APPEND:
		// APPEND mode: No pre-check needed
		// The appender will naturally fail if the table doesn't exist
		break;
	case IngestionMode::REPLACE: {
		// REPLACE mode: CREATE OR REPLACE TABLE
		auto create_sql =
		    BuildCreateTableSQL(effective_catalog, effective_schema, table_name, types, names, false, temporary, true);
		duckdb_result result;
		if (duckdb_query(connection, create_sql.c_str(), &result) == DuckDBError) {
			SetError(error, duckdb_result_error(&result));
			duckdb_destroy_result(&result);
			return ADBC_STATUS_INTERNAL;
		}
		duckdb_destroy_result(&result);
		break;
	}
	case IngestionMode::CREATE_APPEND: {
		// CREATE_APPEND mode: Create if not exists, append if exists
		auto sql = BuildCreateTableSQL(effective_catalog, effective_schema, table_name, types, names, true, temporary);
		duckdb_result result;
		if (duckdb_query(connection, sql.c_str(), &result) == DuckDBError) {
			SetError(error, duckdb_result_error(&result));
			duckdb_destroy_result(&result);
			return ADBC_STATUS_INTERNAL;
		}
		duckdb_destroy_result(&result);
		break;
	}
	}
	AppenderWrapper appender(connection, effective_catalog, effective_schema, table_name);
	if (!appender.Valid()) {
		return ADBC_STATUS_INTERNAL;
	}
	duckdb::ArrowArrayWrapper arrow_array_wrapper;

	// Initialize rows_affected counter if requested
	int64_t affected = 0;

	input->get_next(input, &arrow_array_wrapper.arrow_array);
	while (arrow_array_wrapper.arrow_array.release) {
		DataChunkWrapper out_chunk;
		auto res = duckdb_data_chunk_from_arrow(connection, &arrow_array_wrapper.arrow_array, out_types.Get(),
		                                        &out_chunk.chunk);