Hologres SQL
Generate Hologres-compatible SQL from metadata-provided object and column names. Treat PostgreSQL 11 as the baseline syntax, but use only the subset and extensions that Hologres supports.
Namespaces and identifiers
- Address ordinary objects in the connected database as
schema.table; usepubliconly when metadata or connection context selects it. - Treat the connection database as context, not as an automatic SQL qualifier. Use
external_database.schema.tableonly when metadata identifies a Hologres V3.0+ external database. - Use configured foreign tables for other Hologres databases or external systems instead of assuming generic PostgreSQL cross-database qualification.
- Fold unquoted identifiers to lowercase. Preserve mixed case, reserved words, and special characters with double quotes; do not use backticks or square brackets.
- Avoid names reserved by Hologres, including column names beginning with
hg_and schema names beginning withholo_,hg_, orpg_.
Queries and types
- Use PostgreSQL-style
LIMITandOFFSET, casts, joins, window functions, and expressions only where supported by the target Hologres version. - Prefer
TEXTfor an unbounded string andVARCHAR(n)only when a length bound is meaningful. - Use Hologres-supported PostgreSQL types such as
SMALLINT,INTEGER,BIGINT,NUMERIC,REAL,DOUBLE PRECISION,BOOLEAN,TEXT,BYTEA,DATE,TIMESTAMP, andTIMESTAMPTZaccording to metadata. - Confirm version support before generating newer Hologres types, functions, logical partitions, dynamic tables, or external databases.
Internal table design
- Choose
orientationfromcolumn,row, orrow,columnaccording to the workload. Require a primary key for row-oriented and row-column tables; allow it to be optional for column-oriented tables. - Make every primary-key column
NOT NULL. If a primary-key table has adistribution_key, make it the primary key or a subset of the primary-key columns. - Make
clustering_keyandevent_time_columncolumnsNOT NULLfor Hologres V1.3.28+ unless an explicitly approved compatibility setting permits nullable keys. - Choose
distribution_keyfor common joins, grouping, and shard pruning; chooseclustering_keyfor point or range filters; chooseevent_time_columnfor time-range pruning. - Treat
orientation,distribution_key,clustering_key, andevent_time_columnas creation-time layout decisions that normally require table recreation to change. - Use
WITH (property = 'value', ...)only for Hologres V2.1+. For a version-neutral statement, create the table and callset_table_propertyin the same DDL transaction. - Do not generate
UNIQUE,CHECK, or foreign-key constraints for internal tables. Treat other PostgreSQL clauses such as generated columns and defaults as version-dependent rather than universally available. - Use only supported list-partition syntax and verify partition-column restrictions before generating partitioned DDL.
Writes, transactions, and external data
- Use
INSERT,UPDATE,DELETE, andINSERT ... ON CONFLICTaccording to the table's primary-key and target-version capabilities. - Do not assume PostgreSQL-style multi-statement DML transactions. Use
BEGINandCOMMITfor supported DDL sequences such asCREATE TABLEplusset_table_property. - Treat foreign tables as mappings to MaxCompute, OSS/DLF, or another Hologres source. Do not attach internal-table storage properties to a foreign table.
- Determine foreign-table read/write support from its server, source, and Hologres version. Use
INSERT INTO internal_table SELECT ... FROM foreign_tablewhen data must be stored locally. - Treat
INSERT OVERWRITE,COPY, and newer data-lake write capabilities as version-specific; do not infer support from PostgreSQL alone.
Avoid common dialect leaks
Before returning SQL, reject MySQL backticks, MySQL table options, Snowflake three-part names, unsupported PostgreSQL constraints, unconditional cross-database qualification, and Hologres properties placed outside their supported creation syntax.