Skip to content

Commit 6e9a779

Browse files
committed
add tests
1 parent 0822652 commit 6e9a779

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,4 +771,62 @@ mod tests {
771771

772772
assert_eq!(Err(spi::SpiError::InvalidPosition), query_result);
773773
}
774+
775+
#[pg_test]
776+
fn test_select_value_only_with_key_filter() {
777+
// Test for issue #26: selecting only value column with WHERE clause on key
778+
let (_container, url) = create_container();
779+
780+
create_fdt(url);
781+
782+
// Insert test data
783+
Spi::run("INSERT INTO test (key, value) VALUES ('key1','value1'),('key2','value2'),('key3','value3')")
784+
.expect("INSERT should work");
785+
786+
// Test 1: SELECT value WHERE key = 'key2' should return the value
787+
let query_result = Spi::get_one::<String>("SELECT value FROM test WHERE key = 'key2'")
788+
.expect("SELECT value with key filter should work");
789+
790+
assert_eq!(Some(format!("value2")), query_result);
791+
792+
// Test 2: SELECT key WHERE key = 'key1' should also work
793+
let query_result = Spi::get_one::<String>("SELECT key FROM test WHERE key = 'key1'")
794+
.expect("SELECT key with key filter should work");
795+
796+
assert_eq!(Some(format!("key1")), query_result);
797+
798+
// Test 3: SELECT * WHERE key = 'key3' should work (baseline)
799+
let query_result = Spi::get_two::<String, String>("SELECT * FROM test WHERE key = 'key3'")
800+
.expect("SELECT * with key filter should work");
801+
802+
assert_eq!((Some(format!("key3")), Some(format!("value3"))), query_result);
803+
}
804+
805+
#[pg_test]
806+
fn test_update_value_only_with_key_filter() {
807+
// Test for issue #26: UPDATE with only value column when key is in WHERE clause
808+
let (_container, url) = create_container();
809+
810+
create_fdt(url);
811+
812+
// Insert test data
813+
Spi::run("INSERT INTO test (key, value) VALUES ('gather/78','original_value'),('gather/84','other_value')")
814+
.expect("INSERT should work");
815+
816+
// Update without including key column in SET clause
817+
Spi::run("UPDATE test SET value = 'updated_value' WHERE key = 'gather/84'")
818+
.expect("UPDATE with key filter should work");
819+
820+
// Verify the update worked
821+
let query_result = Spi::get_one::<String>("SELECT value FROM test WHERE key = 'gather/84'")
822+
.expect("SELECT after UPDATE should work");
823+
824+
assert_eq!(Some(format!("updated_value")), query_result);
825+
826+
// Verify other row was not affected
827+
let query_result = Spi::get_one::<String>("SELECT value FROM test WHERE key = 'gather/78'")
828+
.expect("SELECT other row should work");
829+
830+
assert_eq!(Some(format!("original_value")), query_result);
831+
}
774832
}

0 commit comments

Comments
 (0)