Prevent specific column value-rows in a Vertica table
Hello, is there a way to prevent loading rows with specific column values into a Vertica table? For example I have a table that has data for multiple companies and if the column CompanyID=1 I want that data copied, if it is another value, it should not be.
I know it would be ideal to exclude CompanyID<>1 as part of the batch load, but we don't have that option. On relational databases I would create a trigger that would prevent the unwanted rows, how can it be done in Vertica? CompanyID is not the PK.
0
Answers
I can imagine two ways - both not too effective, but there you are.
This CSV file:
pumped through my d2l:
modified and run with vsql:
Load:
Well, finds the error. But rejects everything:
Next try, taking advantage of the fact that we can partition a table and drop its partitions very quickly:
Loading this table:
Loads everything, as expected.
But now:
We don't want
org
to contain anything but 1. So we quickly get rid of all other partitions:Yes, we load too much. But then, our parser is most efficient and will determine the values for org quicker than other methods. And you get rid of the unwanted stuff very quickly ...
In addition to the second solution of @marcothesane, you can provide your users a view on top of the table with the filter org=1 then do the drop partition whenever you want,
In addition, if the "org" field has a wide range of possible values, consider the following example:
Output:
Just because we all like playing, and @mosheg has introduced the derived value in a COPY statement, as an
AS
clause in the column list:You can also formulate a load script to give
org
the same "wrong" value if the input is not equal to 1 - thus avoiding an additional column that is just needed to separate what you want from what you don't want.The content of the input file
foo.csv
is still:Create table:
Copy command:
Control query:
drop the one partition:
Final control query: