Reputation: 80194
Is there a simple and concise way to check that two rows of a given Table contains the same data in all columns?
Upvotes: 0
Views: 246
Reputation: 187399
I haven't tested this, but it seems the most obvious solution:
// get an Sql instance
def db = [url:'jdbc:hsqldb:mem:testDB', user:'sa', password:'',
driver:'org.hsqldb.jdbcDriver']
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
// Get 2 rows
GroovyRowResults row1 = sql.firstRow("select * from user where id = 4")
GroovyRowResults row2 = sql.firstRow("select * from user where email = '[email protected]'")
// compare them
boolean identical = row1.equals(row2)
Upvotes: 1
Reputation: 4624
Not especally Groovy, but I'd make SQL do the lifting a la something like:
db.firstRow("SELECT COUNT(DISTINCT CONCAT(city,state,zip)) FROM Candidates WHERE id IN (1,2)")[0] == 0
Upvotes: 0