4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

SQL Issue: INSERT without column_list

When reviewing application code, I often see INSERT queries that don't specify a column list.

INSERT INTO Table1
VALUES ('Val1', 'Val2', 'Val3'); 

This syntax works great. However, it has an implied dependency on the column definitions of the table. If the table's schema changes, the INSERT would fail... or worse, it would succeed and put the values into the wrong columns.

I normally see this error in application code. In applications, the developer has control over their environment, so assumptions like this are relatively safe. However, in a world where application stitch together data from different sources, assumptions like this can be dangerous. When interacting with any service, it's best to be defensive.

So even though it's a bit more work, specify the column list when INSERTing.

INSERT INTO Table1 (Col1, Col2, Col3)
VALUES ('Val1', 'Val2', 'Val3'); 
36 upvotes $0.23

Replies (3)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: