Skip to content

Instantly share code, notes, and snippets.

@glamp
Last active December 16, 2015 02:09
Show Gist options
  • Save glamp/5360060 to your computer and use it in GitHub Desktop.
Save glamp/5360060 to your computer and use it in GitHub Desktop.
--returns rows in random order
select * from sometable order by random();
--use '::' for casting
select '2013-01-01'::date;
-- date
--------------
-- 2013-01-01
select 1 / 10 as non_casted, 1::float8 / 10 as casted;
-- non_casted | casted
--------------+--------
-- 0 | 0.1
--creating a new table on the fly
select
*
into
newtable
from
oldtable;
--or with a temp table
select
*
into
temp new_temptable
from
oldtable;
@pixeloution
Copy link

order by random() causes a full table scan on mySQL -- which means its generally a bad thing to do on any decent sized table. Not sure if the same holds true in Postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment