clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 936421 fiddles created (12715 in the last week).

CREATE TABLE actor ( actor_id serial, -- PRIMARY KEY -- see below first_name character varying(45) NOT NULL, last_name character varying(45) NOT NULL, last_update timestamptz DEFAULT now() NOT NULL ); CREATE TABLE film ( film_id serial, -- PRIMARY KEY -- see below title character varying(255) NOT NULL, last_update timestamptz DEFAULT now() NOT NULL ); CREATE TABLE film_actor ( actor_id int NOT NULL, film_id int NOT NULL, last_update timestamp without time zone DEFAULT now() NOT NULL -- PRIMARY KEY (film_id, actor_id) -- see below );
 hidden batch(es)


ALTER TABLE actor ADD CONSTRAINT actor_pkey PRIMARY KEY (actor_id); ALTER TABLE film ADD CONSTRAINT film_pkey PRIMARY KEY (film_id); ALTER TABLE film_actor ADD CONSTRAINT film_actor_pkey PRIMARY KEY (film_id, actor_id) , ADD CONSTRAINT film_actor_actor_id_fkey FOREIGN KEY (actor_id) REFERENCES actor(actor_id) , ADD CONSTRAINT film_actor_film_id_fkey FOREIGN KEY (film_id) REFERENCES film(film_id);
 hidden batch(es)


create or replace function random_string(length integer) returns text as $$ declare chars text[] := '{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}'; result text := ''; i integer := 0; begin if length < 0 then raise exception 'Given length cannot be less than 0'; end if; for i in 1..length loop result := result || chars[1+random()*(array_length(chars, 1)-1)]; end loop; return result; end; $$ language plpgsql; insert into film(title) select random_string(30) from generate_series(1,100); insert into actor(first_name, last_name) select random_string(30), random_string(30) from generate_series(1,(select count(*)*5 from film)); insert into film_actor(film_id, actor_id) select film_id, actor_id from film cross join lateral (select actor_id from actor where film_id is not null order by random() limit 2) as actor;
100 rows affected
500 rows affected
200 rows affected
 hidden batch(es)


select * from film_actor;
actor_id film_id last_update
485 1 2020-02-27 13:50:00.52396
330 1 2020-02-27 13:50:00.52396
468 2 2020-02-27 13:50:00.52396
134 2 2020-02-27 13:50:00.52396
443 3 2020-02-27 13:50:00.52396
364 3 2020-02-27 13:50:00.52396
295 4 2020-02-27 13:50:00.52396
219 4 2020-02-27 13:50:00.52396
275 5 2020-02-27 13:50:00.52396
23 5 2020-02-27 13:50:00.52396
301 6 2020-02-27 13:50:00.52396
295 6 2020-02-27 13:50:00.52396
133 7 2020-02-27 13:50:00.52396
256 7 2020-02-27 13:50:00.52396
96 8 2020-02-27 13:50:00.52396
385 8 2020-02-27 13:50:00.52396
430 9 2020-02-27 13:50:00.52396
358 9 2020-02-27 13:50:00.52396
387 10 2020-02-27 13:50:00.52396
301 10 2020-02-27 13:50:00.52396
162 11 2020-02-27 13:50:00.52396
485 11 2020-02-27 13:50:00.52396
416 12 2020-02-27 13:50:00.52396
297 12 2020-02-27 13:50:00.52396
293 13 2020-02-27 13:50:00.52396
355 13 2020-02-27 13:50:00.52396
442 14 2020-02-27 13:50:00.52396
27 14 2020-02-27 13:50:00.52396
100 15 2020-02-27 13:50:00.52396
117 15 2020-02-27 13:50:00.52396
292 16 2020-02-27 13:50:00.52396
427 16 2020-02-27 13:50:00.52396
308 17 2020-02-27 13:50:00.52396
458 17 2020-02-27 13:50:00.52396
70 18 2020-02-27 13:50:00.52396
45 18 2020-02-27 13:50:00.52396
481 19 2020-02-27 13:50:00.52396
44 19 2020-02-27 13:50:00.52396
373 20 2020-02-27 13:50:00.52396
7 20 2020-02-27 13:50:00.52396
229 21 2020-02-27 13:50:00.52396
262 21 2020-02-27 13:50:00.52396
67 22 2020-02-27 13:50:00.52396
350 22 2020-02-27 13:50:00.52396
310 23 2020-02-27 13:50:00.52396
241 23 2020-02-27 13:50:00.52396
428 24 2020-02-27 13:50:00.52396
395 24 2020-02-27 13:50:00.52396
476 25 2020-02-27 13:50:00.52396
109 25 2020-02-27 13:50:00.52396
396 26 2020-02-27 13:50:00.52396
383 26 2020-02-27 13:50:00.52396
166 27 2020-02-27 13:50:00.52396
400 27 2020-02-27 13:50:00.52396
140 28 2020-02-27 13:50:00.52396
163 28 2020-02-27 13:50:00.52396
231 29 2020-02-27 13:50:00.52396
219 29 2020-02-27 13:50:00.52396
498 30 2020-02-27 13:50:00.52396
380 30 2020-02-27 13:50:00.52396
403 31 2020-02-27 13:50:00.52396
359 31 2020-02-27 13:50:00.52396
223 32 2020-02-27 13:50:00.52396
431 32 2020-02-27 13:50:00.52396
449 33 2020-02-27 13:50:00.52396
245 33 2020-02-27 13:50:00.52396
152 34 2020-02-27 13:50:00.52396
218 34 2020-02-27 13:50:00.52396
465 35 2020-02-27 13:50:00.52396
259 35 2020-02-27 13:50:00.52396
430 36 2020-02-27 13:50:00.52396
460 36 2020-02-27 13:50:00.52396
198 37 2020-02-27 13:50:00.52396
228 37 2020-02-27 13:50:00.52396
305 38 2020-02-27 13:50:00.52396
250 38 2020-02-27 13:50:00.52396
155 39 2020-02-27 13:50:00.52396
54 39 2020-02-27 13:50:00.52396
105 40 2020-02-27 13:50:00.52396
205 40 2020-02-27 13:50:00.52396
256 41 2020-02-27 13:50:00.52396
279 41 2020-02-27 13:50:00.52396
234 42 2020-02-27 13:50:00.52396
496 42 2020-02-27 13:50:00.52396
305 43 2020-02-27 13:50:00.52396
199 43 2020-02-27 13:50:00.52396
465 44 2020-02-27 13:50:00.52396
409 44 2020-02-27 13:50:00.52396
425 45 2020-02-27 13:50:00.52396
105 45 2020-02-27 13:50:00.52396
94 46 2020-02-27 13:50:00.52396
135 46 2020-02-27 13:50:00.52396
490 47 2020-02-27 13:50:00.52396
353 47 2020-02-27 13:50:00.52396
32 48 2020-02-27 13:50:00.52396
455 48 2020-02-27 13:50:00.52396
152 49 2020-02-27 13:50:00.52396
122 49 2020-02-27 13:50:00.52396
183 50 2020-02-27 13:50:00.52396
270 50 2020-02-27 13:50:00.52396
229 51 2020-02-27 13:50:00.52396
211 51 2020-02-27 13:50:00.52396
283 52 2020-02-27 13:50:00.52396
460 52 2020-02-27 13:50:00.52396
101 53 2020-02-27 13:50:00.52396
310 53 2020-02-27 13:50:00.52396
210 54 2020-02-27 13:50:00.52396
74 54 2020-02-27 13:50:00.52396
224 55 2020-02-27 13:50:00.52396
474 55 2020-02-27 13:50:00.52396
87 56 2020-02-27 13:50:00.52396
42 56 2020-02-27 13:50:00.52396
243 57 2020-02-27 13:50:00.52396
448 57 2020-02-27 13:50:00.52396
287 58 2020-02-27 13:50:00.52396
260 58 2020-02-27 13:50:00.52396
88 59 2020-02-27 13:50:00.52396
462 59 2020-02-27 13:50:00.52396
267 60 2020-02-27 13:50:00.52396
344 60 2020-02-27 13:50:00.52396
15 61 2020-02-27 13:50:00.52396
340 61 2020-02-27 13:50:00.52396
234 62 2020-02-27 13:50:00.52396
83 62 2020-02-27 13:50:00.52396
66 63 2020-02-27 13:50:00.52396
397 63 2020-02-27 13:50:00.52396
452 64 2020-02-27 13:50:00.52396
358 64 2020-02-27 13:50:00.52396
140 65 2020-02-27 13:50:00.52396
396 65 2020-02-27 13:50:00.52396
255 66 2020-02-27 13:50:00.52396
342 66 2020-02-27 13:50:00.52396
342 67 2020-02-27 13:50:00.52396
423 67 2020-02-27 13:50:00.52396
23 68 2020-02-27 13:50:00.52396
158 68 2020-02-27 13:50:00.52396
402 69 2020-02-27 13:50:00.52396
155 69 2020-02-27 13:50:00.52396
175 70 2020-02-27 13:50:00.52396
434 70 2020-02-27 13:50:00.52396
85 71 2020-02-27 13:50:00.52396
258 71 2020-02-27 13:50:00.52396
385 72 2020-02-27 13:50:00.52396
108 72 2020-02-27 13:50:00.52396
420 73 2020-02-27 13:50:00.52396
59 73 2020-02-27 13:50:00.52396
308 74 2020-02-27 13:50:00.52396
496 74 2020-02-27 13:50:00.52396
437 75 2020-02-27 13:50:00.52396
95 75 2020-02-27 13:50:00.52396
78 76 2020-02-27 13:50:00.52396
98 76 2020-02-27 13:50:00.52396
377 77 2020-02-27 13:50:00.52396
117 77 2020-02-27 13:50:00.52396
192 78 2020-02-27 13:50:00.52396
372 78 2020-02-27 13:50:00.52396
304 79 2020-02-27 13:50:00.52396
16 79 2020-02-27 13:50:00.52396
486 80 2020-02-27 13:50:00.52396
107 80 2020-02-27 13:50:00.52396
310 81 2020-02-27 13:50:00.52396
206 81 2020-02-27 13:50:00.52396
442 82 2020-02-27 13:50:00.52396
25 82 2020-02-27 13:50:00.52396
427 83 2020-02-27 13:50:00.52396
497 83 2020-02-27 13:50:00.52396
65 84 2020-02-27 13:50:00.52396
480 84 2020-02-27 13:50:00.52396
82 85 2020-02-27 13:50:00.52396
64 85 2020-02-27 13:50:00.52396
400 86 2020-02-27 13:50:00.52396
169 86 2020-02-27 13:50:00.52396
113 87 2020-02-27 13:50:00.52396
87 87 2020-02-27 13:50:00.52396
427 88 2020-02-27 13:50:00.52396
346 88 2020-02-27 13:50:00.52396
315 89 2020-02-27 13:50:00.52396
87 89 2020-02-27 13:50:00.52396
410 90 2020-02-27 13:50:00.52396
409 90 2020-02-27 13:50:00.52396
58 91 2020-02-27 13:50:00.52396
192 91 2020-02-27 13:50:00.52396
305 92 2020-02-27 13:50:00.52396
246 92 2020-02-27 13:50:00.52396
230 93 2020-02-27 13:50:00.52396
41 93 2020-02-27 13:50:00.52396
431 94 2020-02-27 13:50:00.52396
417 94 2020-02-27 13:50:00.52396
66 95 2020-02-27 13:50:00.52396
381 95 2020-02-27 13:50:00.52396
402 96 2020-02-27 13:50:00.52396
180 96 2020-02-27 13:50:00.52396
37 97 2020-02-27 13:50:00.52396
448 97 2020-02-27 13:50:00.52396
488 98 2020-02-27 13:50:00.52396
111 98 2020-02-27 13:50:00.52396
35 99 2020-02-27 13:50:00.52396
205 99 2020-02-27 13:50:00.52396
53 100 2020-02-27 13:50:00.52396
109 100 2020-02-27 13:50:00.52396
 hidden batch(es)