Reputation: 33
I want to query a random row selection from a teradata database with SQLAlchemy. Basically I want to translate the following statement (which works for SQLite) so it also works for teradata.
sample = session.query(sample_table_name).order_by(func.random()).limit(1000)
Is there an equivalent for func.random()
which works with teradata? I know that for example for an Oracle DB you need to replace it by text('dbms_random.value')
.
Upvotes: 0
Views: 172
Reputation: 3833
I'm not sure about the sqlalchemy
bit, but you can use SAMPLE
to get a sampling of rows:
-- Pseudo-randomized (faster)
SELECT *
FROM MyTable
SAMPLE 1000
;
-- Simple random sample (takes longer)
SELECT *
FROM MyTable
SAMPLE RANDOMIZED ALLOCATION 1000
;
Upvotes: 1