0

I need to update field named 'from' in postgres. But i can not to do it.

Select working such:

SELECT table_name.from FROM table_name WHERE id=1

But I can not do it with UPDATE:

production=# UPDATE table_name SET from='text' WHERE id=3482;
ERROR:  syntax error at or near "from"
production=# update table_name set table_name.from='text' where id=3482;
ERROR:  column "table_name" of relation "table_name" does not exist
LINE 1: update table_name set table_name.from='

Can you suggest a way to update a field 'from' in the table?

Vlad Kn
  • 141
  • 2
  • 13
  • Have you tried using quotes around the `from` (like `SELECT table_name."from" FROM table_name WHERE id=1`) – Nico Haase Jul 19 '21 at 11:31
  • See https://stackoverflow.com/questions/7651417/escaping-keyword-like-column-names-in-postgres for more details – Nico Haase Jul 19 '21 at 11:31
  • Its not working ERROR: column "table_name" of relation "table_name" does not exist or ERROR: syntax error at or near "'from'" LINE 1: update table_name set table_name.'from'= – Vlad Kn Jul 19 '21 at 11:34
  • 2
    Mandatory read: [Identifiers and Keywords](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS) in the Postgres manual –  Jul 19 '21 at 11:34
  • O! Its working! production=# update "table_name" set "from"='text' where id=3482; UPDATE 1 Thanks! – Vlad Kn Jul 19 '21 at 11:40

2 Answers2

0

Use double quotes as such:

UPDATE table_name SET "from"='text' WHERE id=3482;

Look at 4.1.1. Identifiers and Key Words for more info.

EcksDy
  • 1,289
  • 9
  • 25
-2

Change "from" to Your "Field Name"
UPDATE table_name SET "from" = value1 where id=1