jet icon indicating copy to clipboard operation
jet copied to clipboard

Add values functions

Open Sytten opened this issue 4 years ago • 7 comments

I was trying to do something similar to https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql/42217872#42217872

WITH input_rows(usr, contact, name) AS (
   VALUES
      (text 'foo1', text 'bar1', text 'bob1')  -- type casts in first row
    , ('foo2', 'bar2', 'bob2')
    -- more?
   )

But I don't think there is a VALUES function.

Sytten avatar Jan 12 '21 22:01 Sytten

Looking at it, the WRAP function will be needed for that https://github.com/go-jet/jet/pull/67

Sytten avatar Jan 12 '21 22:01 Sytten

Yeah, VALUES statement is not implemented yet. SELECT can be used for one row and SELECT with UNION ALL can be used for multiple rows. For instance:

input_rows := CTE("input_rows")

stmt := WITH(
	input_rows.AS(
		UNION_ALL(
                        // first row columns has to be aliased
			SELECT(String("foo1").AS("foo"), String("bar1").AS("bar"), String("bob1").AS("bob")),
			SELECT(String("foo2"), String("bar2"), String("bob2")),
		),
	),
)(
	SELECT(input_rows.AllColumns()).
		FROM(input_rows),
)

go-jet avatar Jan 17 '21 13:01 go-jet