Swiftybase
Function StackDatabasePostgresExamples

Update Query

Example 1: Update Data

In this example, we'll use the Postgres Execute function with the Type set to Update to modify data and return the number of affected rows.

Add Postgres Execute Function

Start by adding the Postgres Execute function. Give it a Result Name and set the Type to Update.

Write the SQL Query

In the function configuration, write the SQL query you want to use to update the data.

Assume we have a users table and want to update the name of a user by their id. The users table schema looks like this:

CREATE TABLE public.users (
  id bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL,
  created_at timestamp with time zone NOT NULL DEFAULT now(),
  name text NULL,
  email text NULL,
  age integer NULL,
  activated boolean NULL,
  updated timestamp without time zone NULL,
  CONSTRAINT users_pkey PRIMARY KEY (id)
);

Now write the following update query:

UPDATE users SET name = $1 WHERE id = $2

Fill the Arguments

Provide the values for the update. Make sure the list literal is enabled:

["$upperName", 15]

Testing

When you run the query, it will update the user's name and return the number of affected rows.

On this page