Skip to content

Commit

Permalink
test: add new test & store timestamp instead of text
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgehermo9 committed Dec 15, 2024
1 parent 95768bb commit 270d32c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/sinks/postgres/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn insert_single_event() {
let (config, table, mut connection) = prepare_config().await;
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
let create_table_sql =
format!("CREATE TABLE IF NOT EXISTS {table} (id BIGINT, host TEXT, timestamp TIMESTAMPTZ, message TEXT, payload JSONB)");
format!("CREATE TABLE {table} (id BIGINT, host TEXT, timestamp TIMESTAMPTZ, message TEXT, payload JSONB)");
sqlx::query(&create_table_sql)
.execute(&mut connection)
.await
Expand Down Expand Up @@ -107,7 +107,7 @@ async fn insert_multiple_events() {
let (config, table, mut connection) = prepare_config().await;
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
let create_table_sql = format!(
"CREATE TABLE IF NOT EXISTS {table} (id BIGINT, host TEXT, timestamp TIMESTAMPTZ, message TEXT, payload JSONB)"
"CREATE TABLE {table} (id BIGINT, host TEXT, timestamp TIMESTAMPTZ, message TEXT, payload JSONB)"
);
sqlx::query(&create_table_sql)
.execute(&mut connection)
Expand Down Expand Up @@ -141,7 +141,9 @@ async fn insert_multiple_events() {
assert_eq!(expected_values, actual_values);
}

// Using null::{table} with jsonb_populate_recordset does not work with default values
// Using null::{table} with jsonb_populate_recordset does not work with default values.
// it is like inserting null values explicitly, it does not use table's default values.
//
// https://dba.stackexchange.com/questions/308114/use-default-value-instead-of-inserted-null
// https://stackoverflow.com/questions/49992531/postgresql-insert-a-null-convert-to-default
// TODO: this cannot be fixed without a workaround involving a trigger creation, which is beyond
Expand All @@ -150,8 +152,9 @@ async fn insert_multiple_events() {
async fn default_columns_are_not_populated() {
let (config, table, mut connection) = prepare_config().await;
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
let create_table_sql =
format!("CREATE TABLE IF NOT EXISTS {table} (id BIGINT, not_existing_column TEXT DEFAULT 'default_value')");
let create_table_sql = format!(
"CREATE TABLE {table} (id BIGINT, not_existing_column TEXT DEFAULT 'default_value')"
);
sqlx::query(&create_table_sql)
.execute(&mut connection)
.await
Expand Down

0 comments on commit 270d32c

Please sign in to comment.