Oracle SAMPLE clause: FROM t SAMPLE(n) [SEED(m)] is a syntax error in oracle mode

Ouverte
#2,895 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@muzimu217 y travaille déjà.

Depuis le 23/10/2026.

  • #2897 par @muzimu217 — ouverte

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
25/100
Type d'issue
Fonctionnalité
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
c, postgresql, sql
Domaine
databases

Piste de recherche

Start by reading the Oracle-mode grammar and the existing TABLESAMPLE grammar and tests; the issue identifies the PostgreSQL 19beta1 base and proposes mapping Oracle SAMPLE forms onto existing TABLESAMPLE behavior. Check open pull request #2897 for the current implementation direction. Done means the listed SAMPLE, SAMPLE BLOCK, SEED, and trailing-alias examples parse in oracle mode with the proposed mappings and regression coverage.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Description

Oracle applications sample tables with the SAMPLE clause of the FROM
list: SAMPLE (percentage) selects a random fraction of the rows,
SAMPLE BLOCK (percentage) a fraction of blocks, and SEED (seed_value)
makes the sample reproducible:

SELECT * FROM employees SAMPLE(10);
SELECT * FROM employees SAMPLE BLOCK(15) SEED(42);
SELECT * FROM employees SAMPLE(10) e WHERE e.deptno = 20;

In oracle mode every one of these is a syntax error today, because the
oracle grammar only knows PostgreSQL's TABLESAMPLE spelling:

SELECT * FROM dual SAMPLE(50);
-- ERROR:  syntax error at or near "(" ... (SAMPLE parses as a table alias)

Migrated quality-check, backfill and reporting SQL therefore needs a manual
rewrite to TABLESAMPLE bernoulli/system, and the alias has to move to the
other side of the clause, since PostgreSQL's spelling puts the alias before
the sample while Oracle puts it after.

Expected behaviour

SAMPLE (n) [SEED (m)] (and SAMPLE BLOCK (n) [SEED (m)]) parse in oracle
mode, with the alias allowed after the clause per the Oracle spelling.

Actual behaviour

Syntax error; the word SAMPLE is taken for a table alias and the
parenthesized percentage fails to parse.

Proposal

Parse the clause as sugar over the existing TABLESAMPLE machinery, so no
new sampling code enters the executor:

  • SAMPLE (n) → TABLESAMPLE bernoulli (n) — the per-row selection
    probability of bernoulli matches Oracle's documented row-level sampling;
  • SAMPLE BLOCK (n) → TABLESAMPLE system (n) — block-level sampling;
  • SEED (m) → REPEATABLE (m).

SAMPLE and SEED would join TABLESAMPLE in the type_func_name keyword
class (they stop being usable as a bare column reference or table alias,
exactly the trade-off PostgreSQL made for TABLESAMPLE itself), and BLOCK
becomes an unreserved keyword, which stays usable as a name.

Environment

IvorySQL master @ 5aa044b341 (PostgreSQL 19beta1 base), cluster created
with initdb -m oracle.

Langage dominant
C
Étoiles
1.1k
Forks
232
Merge moyen
2 j 3 h
PR mergées (30 j)
8

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de IvorySQL/IvorySQL

Toutes les issues de IvorySQL/IvorySQL

Issues similaires

Plus d'issues C

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.