Skip to content

Commit

Permalink
Format RETURNS TABLE (..)
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Jan 27, 2024
1 parent 46be069 commit dbda44b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/syntax/data_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isArray } from "../utils";
import { CstToDocMap } from "../CstToDocMap";
import { group, indent, softline } from "../print_utils";

export const dataTypeMap: Partial<CstToDocMap<AllDataTypeNodes>> = {
export const dataTypeMap: CstToDocMap<AllDataTypeNodes> = {
// print single-word types as `TYPE(10)` and multi-word types as `MY TYPE (10)`
named_data_type: (print, node) =>
(isArray(node.nameKw) ? print.spaced : print)(["nameKw", "params"]),
Expand All @@ -16,4 +16,5 @@ export const dataTypeMap: Partial<CstToDocMap<AllDataTypeNodes>> = {
array_type_param: (print) => print.spaced(["dataType", "constraints"]),
struct_type_param: (print) =>
print.spaced(["name", "dataType", "constraints"]),
table_data_type: (print) => print.spaced(["tableKw", "columns"]),
};
12 changes: 10 additions & 2 deletions test/ddl/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,24 @@ describe("function", () => {

it(`formats RETURNS clause`, async () => {
await testBigquery(dedent`
CREATE FUNCTION IF NOT EXISTS my_func()
CREATE FUNCTION my_func()
RETURNS INT64
AS
(SELECT 1)
`);
});

it(`formats RETURNS TABLE`, async () => {
await testPostgresql(dedent`
CREATE FUNCTION foo()
RETURNS TABLE (id INT, name TEXT)
AS 'SELECT 1'
`);
});

it(`formats OPTIONS (...)`, async () => {
await testBigquery(dedent`
CREATE FUNCTION IF NOT EXISTS my_func()
CREATE FUNCTION my_func()
AS
(SELECT 1)
OPTIONS (description = 'constant-value function')
Expand Down

0 comments on commit dbda44b

Please sign in to comment.