When I do SELECT statements in PHP code I always select named columns, like:
SELECT id, name from users;
rather than using:
SELECT * from users;
This has the advantage of being more informative and readable, and also avoids problems later if new columns are added to the table.
What I’m wondering is, is it possible to use the same idea in an INSERT statement? I’m imagining it might be something like this:
INSERT into people values (id=1, name='Fred');
The syntax as I’ve shown in this example doesn’t work, but I wonder if something equivalent is possible? If not, does anyone know why not? Is it a deliberate omission?
That’s syntax is possible with MySQL only. Afaik, other RDBMS doesn’t allow that. Here’s the syntax:
I wish PostgreSQL facilitated this kind of insert syntax
Standard ANSI syntax, however, would be
INSERT into people (yr, city) values (2012, ‘London’);