Last active
December 16, 2015 02:09
-
-
Save glamp/5360060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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