mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(curriculum): clarify error when inserting without columns (#65133)
Co-authored-by: Jeevankumar-S <jeevenkumar2003@email.com>
This commit is contained in:
co-authored by
Jeevankumar-S
parent
f66ec56ab6
commit
071374ca02
+5
-1
@@ -47,7 +47,11 @@ INSERT INTO dogs
|
||||
VALUES ('Gino', 3);
|
||||
```
|
||||
|
||||
This is valid too, but it's more prone to errors because the values are assigned to the columns based on their order.
|
||||
This syntax is valid SQL, but it is error-prone.
|
||||
|
||||
Since values are assigned based on column order, PostgreSQL will try to insert `'Gino'` into the `id` column, which expects an integer. This results in an error such as `invalid input syntax for type integer`.
|
||||
|
||||
For this reason, it is safer to explicitly specify the column names when inserting data.
|
||||
|
||||
You can also insert multiple records in the same SQL command by separating them with a comma.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user