squirrel icon indicating copy to clipboard operation
squirrel copied to clipboard

Select FROM stored procedure

Open lgopalab opened this issue 4 years ago • 2 comments

Currently there is no way of executing queries like SELECT * FROM my_stored_proc(a,b,c) as FROM clause only accepts a single string as argument. https://github.com/Masterminds/squirrel/blob/75b018d6ca72f526bf83d5ae500841097c458bea/select.go#L274 Simply by making the function to accept variadic arguments, we can achieve a basic solution.

func (b SelectBuilder) FromProc(from string, args ...interface{}) SelectBuilder {
	from = from+"("+Placeholders(len(args))+")"
	return builder.Set(b, "From", newPart(from, args...)).(SelectBuilder)
}

This can be invoked as follows

Select("*").FromProc("my_stored_proc",args[:]...)

I'm not sure if this is an acceptable solution. But It does simplify some workflows.

lgopalab avatar Feb 04 '22 14:02 lgopalab

Just saw this. https://github.com/Masterminds/squirrel/issues/294 These are similar.

lgopalab avatar Feb 04 '22 14:02 lgopalab

Yes! This is the only case, in our codebase, where we need to construct a piece of sql (the store procedure call) using fmt.Sprintf

dvd0101 avatar Sep 14 '22 16:09 dvd0101