-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sql_addition config for writers, which allows UPSERT.
This commit adds a "sql_addition" configure option for the PostgreSQL writer, which allows, e.g., to insert an UPSERT option after the insert call that is constructed by the plugin. For a complete example, see the write-upsert testcase, which uses this command to create a filter: local filter: Log::Filter = [$name="postgres", $path="testtable", $writer=Log::WRITER_POSTGRESQL, $config=table(["dbname"]="testdb", ["port"]="7772", ["sql_addition"]="ON CONFLICT (i) DO UPDATE SET s=EXCLUDED.s")];
- Loading branch information
Showing
4 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
i|s | ||
-42|hurz2 | ||
(1 row) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# @TEST-SERIALIZE: postgres | ||
# @TEST-EXEC: initdb postgres | ||
# @TEST-EXEC: perl -pi.bak -E "s/#port =.*/port = 7772/;" postgres/postgresql.conf | ||
# @TEST-EXEC: pg_ctl start -D postgres -l serverlog | ||
# @TEST-EXEC: sleep 5 | ||
# @TEST-EXEC: createdb -p 7772 testdb | ||
# @TEST-EXEC: psql -p 7772 testdb < create.sql | ||
# @TEST-EXEC: bro %INPUT || true | ||
# @TEST-EXEC: echo "select * from testtable" | psql -A -p 7772 testdb >ssh.out 2>&1 || true | ||
# @TEST-EXEC: pg_ctl stop -D postgres -m fast | ||
# @TEST-EXEC: btest-diff ssh.out | ||
|
||
@TEST-START-FILE create.sql | ||
create table testtable ( | ||
i integer not null unique, | ||
s varchar not null unique); | ||
@TEST-END-FILE | ||
|
||
# Test all possible types. | ||
|
||
module SSHTest; | ||
|
||
export { | ||
redef enum Log::ID += { LOG }; | ||
|
||
type Log: record { | ||
i: int; | ||
s: string; | ||
} &log; | ||
} | ||
|
||
function foo(i : count) : string | ||
{ | ||
if ( i > 0 ) | ||
return "Foo"; | ||
else | ||
return "Bar"; | ||
} | ||
|
||
event bro_init() | ||
{ | ||
Log::create_stream(SSHTest::LOG, [$columns=Log]); | ||
local filter: Log::Filter = [$name="postgres", $path="testtable", $writer=Log::WRITER_POSTGRESQL, $config=table(["dbname"]="testdb", ["port"]="7772", ["sql_addition"]="ON CONFLICT (i) DO UPDATE SET s=EXCLUDED.s")]; | ||
Log::add_filter(SSHTest::LOG, filter); | ||
|
||
local empty_set: set[string]; | ||
local empty_vector: vector of string; | ||
|
||
Log::write(SSHTest::LOG, [ | ||
$i=-42, | ||
$s="hurz" | ||
]); | ||
|
||
Log::write(SSHTest::LOG, [ | ||
$i=-42, | ||
$s="hurz2" | ||
]); | ||
} | ||
|