SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
A
A
A
Share
Blog
Popular
SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code.
You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.
SQL code:
Upload
Copy
Format
Clear
CREATE TABLE auctioneer ( event_id INTEGER, firstname TEXT, lastname TEXT, nickname TEXT, email TEXT ); CREATE TABLE attachment ( event_id INTEGER, filename TEXT, datacenter TEXT, localname TEXT ); CREATE TABLE bet ( event_id INTEGER, volume NUMERIC, ts TIMESTAMP ); CREATE OR REPLACE FUNCTION auctioneer_to_json(event_id INTEGER) RETURNS TEXT LANGUAGE plpgsql AS $$ DECLARE firstname_ TEXT; lastname_ TEXT; nickname_ TEXT; email_ TEXT; BEGIN SELECT firstname, lastname, nickname, email INTO firstname_, lastname_, nickname_, email_ FROM auctioneer WHERE auctioneer.event_id = $1; RETURN format( '{"firstname": %I, "lastname": %I, "nickname": %I, "email": %I}', firstname_, lastname_, nickname_, email_ ); END; $$; CREATE OR REPLACE FUNCTION attachment_to_json(event_id INTEGER) RETURNS TEXT LANGUAGE plpgsql AS $$ DECLARE filename_ TEXT; datacenter_ TEXT; localname_ TEXT; BEGIN SELECT filename, datacenter, localname INTO filename_, datacenter_, localname_ FROM attachment WHERE attachment.event_id = $1; RETURN format( '{"filename": %I, location": {"datacenter": %I, "localname": %I}}', filename_, datacenter_, localname_ ); END; $$; CREATE OR REPLACE FUNCTION bet_to_json(event_id INTEGER) RETURNS TEXT LANGUAGE plpgsql AS $$ DECLARE volume_ NUMERIC; ts_ TIMESTAMP; BEGIN SELECT volume, ts INTO volume_, ts_ FROM bet WHERE bet.event_id = $1; RETURN format( '{"volume": %s, "ts": %s}', volume_, EXTRACT(EPOCH FROM ts_)::BIGINT ); END; $$; CREATE OR REPLACE VIEW v_auction_payload(payload) AS SELECT format( '{"auctioneer": %s, "attachment": %s, "bet": %s}', auctioneer_to_json(bet.event_id), attachment_to_json(bet.event_id), bet_to_json(bet.event_id) ) FROM auctioneer JOIN attachment ON auctioneer.event_id = attachment.event_id JOIN bet ON attachment.event_id = bet.event_id; CREATE OR REPLACE FUNCTION checker() RETURNS TRIGGER AS $$ DECLARE dataarray json; BEGIN INSERT INTO auctioneer (event_id, firstname, lastname, nickname, email) VALUES (1, 't', 't', 't', 't'); /*VALUES (NEW.event_id, NEW.firstname, NEW.lastname, NEW.nickname, NEW.nickname);*/ RETURN NULL; END; $$ LANGUAGE plpgsql; CREATE OR REPLACE TRIGGER reminder1 INSTEAD OF INSERT ON v_auction_payload FOR EACH ROW EXECUTE FUNCTION checker(); INSERT INTO v_auction_payload(payload) VALUES ( '{ "auctioneer": { "firstname": "john", "lastname": "doe", "nickname": "mr.notknown", "email": "john.doe@email.com" }, "attachment": { "filename": "key.token1", "location": { "datacenter": "AWS_EU", "localname": "iD1234sdv23r23rtfwv" } }, "bet": { "volume": 0.00001, "ts": 1672520400 } }'); /*INSERT INTO v_auction_payload(payload) VALUES ( '{ "auctioneer": { "firstname": "john", "lastname": "doe", "nickname": "mr.notknown", "email": "john.doe@email.com" }, "attachment": { "filename": "key.token2", "location": { "datacenter": "AWS_US", "localname": "iDasd@-asfasf23@3s" } }, "bet": { "volume": 0.00085, "ts": 1676928960 } }');*/ CREATE OR REPLACE VIEW auctioneer AS SELECT auctioneer_to_json(*); SELECT * FROM auctioneer;
SQL
Server:
MariaDB 11.4
MariaDB 11.5
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
SQLite 3
SQLite 3 Preloaded
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear