Is it possible to query "INSERT INTO table SET field = 'value' " in Postgresql?

Asked

Viewed 451 times

2

It is possible to run the query INSERT INTO nome_tabela SET nome_campo = 'aaaa' in the Postgresql database.

I had to migrate a virtual store made in PHP with bank Mysql, for Postgresql.

The bank migration part I got with the help of a program and it worked.

Fortunately, the former programmer used PDO to program, which has helped me a lot, but many darlings of INSERT are written the way I described it here.

I’m using version 10.

  • Already tested to see if it works?

  • According to the documentation, you can use the set if you use the DO UPDATE. In this case, I would recommend you take a study in ORM as well.

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.

1 answer

4

Is not possible.

This is one of the problems of doing something out of the norm.

Actually this is a great demonstration that migrating database used by an application is not something trivial and does not work automatically.

Unfortunately the biggest problems are not so visible and cause huge problems without being noticed soon and people tend to think it’s something else, including blaming DB and always someone will argue that should not have migrated because it proved worse than it was "sold".

Unfortunately PDO was used. His only real advantage is an illusion. Migrating from a database involves a full reassessment of the semantics of data access. PDO only helps a little in the syntax that is the easy part. So PDO helps less than 10 percent, probably a lot less, in migration. But the most tragic thing is that it gives the illusion that it helped close or 100%, which is not true.

If it causes little trouble it’s because it was bad before.

An ORM can have the same or worse effect. ORM is useful in some scenarios, but database exchange is an illusion. In fact it is worse because it tends to leave the bad access always, a layer like PDO, if done right, can get good and would only get bad in case of migration.

Here we always see questions talking about these things and the person thinks that "will press a button" and everything will be solved. Architecture problems are the hardest to solve and unfortunately few people know how to do architecture, most believe in things that are not based on engineering, only marketing.

So when a person uses PDO and uses syntax that can’t be migrated, they didn’t know what they were doing. If the person did wrong in the syntax, which is the easy part, imagine in the semantics.

  • Thank you so much for the reply @Maniero. I agree with many things you mentioned. As I am still in the process of learning, I will try to focus my studies on these issues that you addressed. I have really tried to run this query and Postgresql does not work that way. I thank you for your help. Problem solved with the syntax "INSERT INTO table(field) VALUES('value')"

  • 2

    +1, in particular by "PDO legend". Here is further proof that this conversation is more "marketing" than anything. @Gabriel probably the solution in your case is a simple search-replace in SQL to suit the syntax, virtually all code editors do it one way or another.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.