Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table users ( id serial primary key, name varchar, balance int check (balance>=0) ); create table transactions ( id serial primary key, user_id int, amount int, created_at timestamp, description varchar, constraint user_id_fk foreign key (user_id) references users(id) ); create or replace function transaction(_user_id int, _amount int, _description varchar) RETURNS void LANGUAGE plpgsql AS $fnc$ begin insert into transactions ( user_id, amount, created_at, description ) values ( _user_id, _amount, now(), _description ); update users set balance = balance + _amount where id = _user_id; end; $fnc$; insert into users values (1, 'U', 95); select from transaction(1, 10, 'test'); select * from users;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear