Skip to content

Commit b7dbd03

Browse files
committed
test: add fixtures for OUT parameters with SELECT INTO multiple variables
Add Test 15 and Test 16 to exercise the pattern used in auth functions (sign_in, sign_up) where multiple OUT parameters are populated from a single SELECT statement. Test 15: OUT parameters with SELECT INTO multiple variables - Demonstrates plaintext token generation with hash storage - Uses uuid_generate_v5 for deterministic ID from token - SELECT INTO populates 6 OUT parameters from tokens table Test 16: OUT parameters with SELECT INTO STRICT - Tests STRICT modifier with multiple INTO targets
1 parent 132971c commit b7dbd03

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

__fixtures__/plpgsql/plpgsql_deparser_fixes.sql

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,47 @@ LANGUAGE plpgsql AS $$
162162
BEGIN
163163
RAISE NOTICE '%', p_message;
164164
END$$;
165+
166+
-- Test 15: OUT parameters with SELECT INTO multiple variables
167+
-- This pattern is used in auth functions (sign_in, sign_up) where we need to
168+
-- populate multiple OUT parameters from a single SELECT statement
169+
CREATE FUNCTION test_out_params_select_into(
170+
p_user_id uuid,
171+
OUT id uuid,
172+
OUT user_id uuid,
173+
OUT access_token text,
174+
OUT access_token_expires_at timestamptz,
175+
OUT is_verified boolean,
176+
OUT totp_enabled boolean
177+
)
178+
LANGUAGE plpgsql AS $$
179+
DECLARE
180+
v_token_id uuid;
181+
v_plaintext_token text;
182+
BEGIN
183+
v_plaintext_token := encode(gen_random_bytes(48), 'hex');
184+
v_token_id := uuid_generate_v5(uuid_ns_url(), v_plaintext_token);
185+
186+
INSERT INTO tokens (id, user_id, access_token_hash)
187+
VALUES (v_token_id, p_user_id, digest(v_plaintext_token, 'sha256'));
188+
189+
SELECT tkn.id, tkn.user_id, v_plaintext_token, tkn.access_token_expires_at, tkn.is_verified, tkn.totp_enabled
190+
INTO id, user_id, access_token, access_token_expires_at, is_verified, totp_enabled
191+
FROM tokens AS tkn
192+
WHERE tkn.id = v_token_id;
193+
194+
RETURN;
195+
END$$;
196+
197+
-- Test 16: OUT parameters with SELECT INTO and STRICT
198+
CREATE FUNCTION test_out_params_strict(
199+
p_id uuid,
200+
OUT name text,
201+
OUT email text
202+
)
203+
LANGUAGE plpgsql AS $$
204+
BEGIN
205+
SELECT u.name, u.email INTO STRICT name, email
206+
FROM users u
207+
WHERE u.id = p_id;
208+
END$$;

0 commit comments

Comments
 (0)