Skip to content

Commit

Permalink
postmess
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoy-googly-moogly committed Nov 29, 2024
1 parent 47c427f commit bfda7da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 3 additions & 4 deletions packages/malloy/src/dialect/pg_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ export abstract class PostgresBase extends Dialect {
}

sqlLiteralRecord(_lit: RecordLiteralNode): string {
throw new Error('Cannot create a record literal for postgres');
throw new Error('Cannot create a record literal for postgres base dialect');
}

sqlLiteralArray(lit: ArrayLiteralNode): string {
const array = lit.kids.values.map(val => val.sql);
return '{' + array.join(',') + '}';
sqlLiteralArray(_lit: ArrayLiteralNode): string {
throw new Error('Cannot create array literal for postgres base dialect');
}
}
16 changes: 16 additions & 0 deletions packages/malloy/src/dialect/postgres/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
TypecastExpr,
MeasureTimeExpr,
LeafAtomicTypeDef,
RecordLiteralNode,
ArrayLiteralNode,
} from '../../model/malloy_types';
import {
DialectFunctionOverloadDef,
Expand Down Expand Up @@ -445,4 +447,18 @@ export class PostgresDialect extends PostgresBase {
// Square Brackets: INT64[]
return sqlType.match(/^[A-Za-z\s(),[\]0-9]*$/) !== null;
}

sqlLiteralRecord(lit: RecordLiteralNode): string {
const props: string[] = [];
for (const [kName, kVal] of Object.entries(lit.kids)) {
props.push(`"${kName}": ${kVal.sql}`);
}
return `{${props.join(',')}}::jsonb`;
}

sqlLiteralArray(lit: ArrayLiteralNode): string {
// mtoy todo real quoting of values ... strings with quotes will break thi
const array = lit.kids.values.map(val => val.sql);
return `'[${array.join(',')}]'::jsonb`;
}
}
2 changes: 1 addition & 1 deletion test/src/databases/all/compound-atomic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe.each(runtimes.runtimeList)(
const nameOfArrayLenFunction = {
'duckdb': 'LEN',
'standardsql': 'ARRAY_LENGTH',
'postgres': 'ARRAY_LENGTH',
'postgres': 'JSONB_ARRAY_LENGTH',
'presto': 'CARDINALITY',
'trino': 'CARDINALITY',
'mysql': 'JSON_LENGTH',
Expand Down

0 comments on commit bfda7da

Please sign in to comment.