Postgres fails when I use limit with update statement
I want to update just the first record of a table
UPDATE test1 SET name="user101" LIMIT 1;
this fails in postgres as I am using limit;
I can do this
UPDATE test1 SET name="user101"
WHERE ID =(SELECT ID FROM test1 LIMIT 1)
But to use the above sql I should know the column name (ID) and I don't have access to column name in my case.
I need a sql statement that does not require column name but updates only the first record.
Update:
I am using ruby @db.exec(query) to execute query
We pass different sql statements like below to the method which calls @db.exec(query)
- update table1 set t1_name = "123" limit 1;
- update table2 set something = "xyz" limit 1;
- update table3 set som = "abc" limit 1;
now before calling @db.exec(query)
I want to modify the query such that the query won't use limit
In this case I have access to table name, column name that I want to update. But I don't have access to any other column names (ID).
test1when you don't have access to the column names?