[Tarantool-patches] [PATCH] sql: reset values to be bound after execution
Nikita Pettik
korablev at tarantool.org
Mon Apr 6 15:15:51 MSK 2020
On 03 Apr 23:23, Eugene Leonovich wrote:
> On Fri, Apr 3, 2020 at 8:22 PM Nikita Pettik <korablev at tarantool.org> wrote:
>
> > +execute(s.stmt_id, {{[':a'] = 1}, {[':b'] = 2}});
> > + | ---
> > + | - metadata:
> > + | - name: :a
> > + | type: integer
> > + | - name: :b
> > + | type: integer
> > + | - name: :c
> > + | type: boolean
> > + | rows:
> > + | - [1, 2, null]
> >
>
> I wonder, shouldn't an error be thrown if there are not enough parameters
> passed?
I guess it works just as it was implemented long ago. Some users may
rely on this 'feature'. So personally I would rather not change it.
> I just checked Postgres and MySQL, optional parameters are forbidden on
> both systems:
>
> Postgres
> ------------------------------------------------------------------------------------------
> PREPARE foo (int, int, int) AS SELECT $1, $2, $3;
> EXECUTE foo(1, 2, 3);
> ?column? | ?column? | ?column?
> ----------+----------+----------
> 1 | 2 | 3
> (1 row)
>
> EXECUTE foo(1, 2);
> ERROR: wrong number of parameters for prepared statement "foo"
> DETAIL: Expected 3 parameters but got 2.
> ------------------------------------------------------------------------------------------
>
> MySQL
> ------------------------------------------------------------------------------------------
> PREPARE foo FROM 'SELECT ?, ?, ?';
>
>
> SET @a = 1;
>
>
> SET @b = 2;
>
>
> SET @c = 3;
> EXECUTE foo USING @a, @b, @c;
> +------+------+------+
> | ? | ? | ? |
> +------+------+------+
> | 0x31 | 0x32 | 0x33 |
> +------+------+------+
>
> EXECUTE foo USING @a, @b;
> ERROR 1210 (HY000): Incorrect arguments to EXECUTE
> ------------------------------------------------------------------------------------------
>
>
> --
> Thank you and best regards,
> Eugene Leonovich
More information about the Tarantool-patches
mailing list