Swiftybase
Function StackDatabasePostgresExamples

Delete Query

Example 1: Delete Data

In this example, we'll use the Postgres Execute function with the Type set to Delete to delete 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 Delete.

Write the SQL Query

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

Assume we have a users table and want to delete users where id > 10. The 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 delete query:

DELETE FROM users WHERE id > $1

Fill the Arguments

Provide the value for the id condition. Make sure the list literal is enabled:

[15]

Testing

When you run the query, it will delete any user with an id greater than 15 and return the number of rows affected.

On this page