Cast row function : Row « Select Query « PostgreSQL

Home
PostgreSQL
1.Aggregate Functions
2.Analytical Functions
3.Array
4.Constraints
5.Cursor
6.Data Type
7.Database
8.Date Timezone
9.Index
10.Inheritance
11.Insert Delete Update
12.Math Functions
13.Postgre SQL
14.Select Query
15.Sequence
16.Store Procedure Function
17.String Functions
18.Subquery
19.Table
20.Table Joins
21.Transaction
22.User Previliege
23.View
PostgreSQL » Select Query » Row 
Cast row function


postgres=#
postgres=# CREATE FUNCTION getf1(mytableRETURNS int
postgres-# AS 'SELECT $1.f1'
postgres-# LANGUAGE SQL;
CREATE FUNCTION
postgres=#
postgres=# CREATE TYPE myrowtype AS (f1 int, f2 text, f3 numeric);
CREATE TYPE
postgres=#
postgres=# CREATE FUNCTION getf1(myrowtypeRETURNS int
postgres-# AS 'SELECT $1.f1'
postgres-# LANGUAGE SQL;
CREATE FUNCTION
postgres=#
postgres=# SELECT getf1(ROW(1,2.5,'this is a test')::mytable);
 getf1
-------
     1
(row)

postgres=#
postgres=# SELECT getf1(CAST(ROW(11,'this is a test',2.5AS myrowtype));
 getf1
-------
    11
(row)

postgres=#
postgres=# drop function getf1(myrowtype);
DROP FUNCTION
postgres=# drop type myrowtype;
DROP TYPE
postgres=# drop table mytable cascade;
NOTICE:  drop cascades to function getf1(mytable)
DROP TABLE
postgres=#
postgres=#
           
       
Related examples in the same category
1.Row Constructors
2.Pass 'row' function to function
3.Using 'Row' function in a function
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.