reece

simple table function

Dec 6th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.49 KB | None | 0 0
  1. -- \i ~/sandbox/postgresql/table-function.sql
  2. -- reece=> select * from in_out('foo');
  3. --  op  | opn | opd | len
  4. -- -----+-----+-----+-----
  5. --  ins |   2 | ACT |   3
  6.  
  7. CREATE TYPE in_out_result AS (
  8.   op text,
  9.   opn INT,
  10.   opd text,
  11.   len INT
  12. );
  13.  
  14.  
  15. CREATE OR REPLACE FUNCTION in_out(IN s text)
  16. RETURNS SETOF in_out_result
  17. LANGUAGE 'plpgsql'
  18. AS $_$
  19. DECLARE
  20.   r in_out_result%rowtype;
  21. BEGIN
  22.   r.op = 'ins';
  23.   r.opn = 2;
  24.   r.opd = 'ACT';
  25.   r.len = 3;
  26.   RETURN NEXT r;
  27. END
  28. $_$;
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment