Pervasive PSQL System Stored Procedures
The system stored procedures help you accomplish those administrative and informative tasks that are not covered by the Data Definition Language. The system stored procedures have a psp_ prefix.
*Note: Since the system stored procedure names use the psp_ prefix, do not create any stored procedures with the psp_ prefix. Any user-created stored procedure with the same name as that of a system stored procedure will never be executed.
The following table lists the system stored procedures currently supported.
Unless otherwise noted, the code examples for the system stored procedures refer to the Demodata sample database provided with Pervasive PSQL or to Pervasive PSQL system tables. (For default locations of Pervasive PSQL files, see Where are the Pervasive PSQL files installed? in Getting Started With Pervasive PSQL.)
If you execute a system stored procedure in the context of a database (for example, A) and try to obtain information from a secured database (for example, B), an error message appears. You cannot obtain information from a secured database from any other database.
psp_columns
Returns the list of columns and their corresponding information for a specified table, from the current database or the specified database.
Syntax
call psp_columns(['database_qualifier'],'table_name', ['column_name'])
Arguments
 
Returned Result Set
 
Examples
create table tx (c_binary BINARY(10),
c_char CHAR(10),
c_tinyint TINYINT,
c_smallint SMALLINT,
c_int INT,
c_bigint BIGINT,
c_utinyint UTINYINT)
call psp_columns(, 'tx',)
Result Set
Legend: P = Precision; L = Length; S = Scale; R = Radix; N = Nullable; R = Remarks
============ 
Assume that you have a database named "mydatabase" that contains a table named "tx."
call psp_columns('mydatabase', 'tx', )
Result Set
Legend: P = Precision; L = Length; S = Scale; R = Radix; N = Nullable; R = Remarks
============ 
call psp_columns('mydatabase', 'tx', 'c_binary')
Result Set
Legend: P = Precision; L = Length; S = Scale; R = Radix; N = Nullable; R = Remarks
Error Conditions
database_qualifier is a blank string
database_qualifier is an undefined database
table_name is undefined in the database
table_name is a blank string
column_name is a blank string
column_name is undefined in the table
psp_column_attributes
Returns the list of column attributes and the corresponding information from the current database or the specified database.
Syntax
call psp_column_attributes(['database_qualifier'], ['table_name'], ['column_name'])
Arguments
 
Returned Result Set
 
Examples
create table tx (c_binary binary (10) default 01,
c_char char (11) default 'thisisatest',
c_tinyint TINYINT,
c_SMALLINT SMALLINT,
c_int INT,
c_bigint BIGINT,
c_utinyint uTINYINT)
call psp_column_attributes(, , )
Result Set
============ 
create table tlogicalmv (col1 integer, col2 char(20))
alter table tlogicalmv psql_move col1 to 2
call psp_column_attributes(, 'tlogicalmv' , )
Result Set
============ 
call psp_column_attributes(, 'tx', 'c_binary')
Result Set
Error Conditions
database_qualifier is a blank string
database_qualifier is an undefined database
table_name is undefined in the database
table_name is a blank string
column_name is a blank string
column_name is undefined in the table
psp_column_rights
Returns the list of column rights and corresponding information for the specified table, from the current database or the specified database.
*Note: This system stored procedure returns the list of column rights only if it has been explicitly specified using the GRANT syntax.
Syntax
call psp_column_rights(['database_qualifier'], 'table_name', ['column_name'], ['user_name'])
Arguments
 
Returned Result Set
 
Examples
Assume that the following permissions exist for the DEMODATA sample database:
GRANT SELECT(Name, Building_Name) ON Dept TO John
GRANT UPDATE(Name) ON Dept TO Mary
GRANT INSERT(Building_Name) ON Dept TO John
 
Call psp_column_rights(,'Dept', ,'%')
Result Set
*Note: The Master user does not have explicit column rights defined, so psp_column_rights does not return any results for user "Master."
============ 
Assume that user “John” is logged on the database. The following statement prints the column permissions on the “Dept” table for the current user (John).
call psp_column_rights ('demodata', 'Dept', ,)
Result Set
*Note: If a user has been granted rights at the table level (for example, GRANT SELECT ON Dept TO Mary), a call to psp_column_rights does not return any rights. The rights were granted to the table, not to specific columns.
============ 
The following statement prints the column permissions on the “Dept” table for column “Name” for the current user.
call psp_column_rights ('demodata', 'dept', 'name',)
Result Set
============ 
The following statement prints the column permissions on the “Dept” table for user “Mary.”
call psp_column_rights('demodata', 'dept', , 'Mary')
Result Set
Error Conditions
database_qualifier is a blank string
table_name is a blank string
column_name is a blank string
user_name is a blank string
psp_fkeys
Returns the foreign key information for the specified table in the current database.
Syntax
call psp_fkeys(['table_qualifier'], 'pkey_table_name', ['fkey_table_name'])
Arguments
 
Returned Result Set
 
Examples
CREATE TABLE Employee
(
Id INTEGER NOT NULL,
Name VARCHAR(50) NOT NULL,
SupId INTEGER NOT NULL
)
 
ALTER TABLE Employee
ADD CONSTRAINT EmpPkey
PRIMARY KEY(Id)
 
ALTER TABLE Employee
ADD CONSTRAINT ForgnKey
FOREIGN KEY(SupId) REFERENCES
Employee(Id) ON DELETE CASCADE
 
call psp_fkeys(,'Employee',)
Result Set
Legend: PkQ = Pkey_ table_ qualifier; PkO = Pkey_table_owner; PkT = Pktable_ name; PkCol = Pk_ column_ name; Seq = Key_seq; FkQ = Fktable_qualifier; FkO = Fktable_owner; FkT = Fktable_name; FkCol = Fkcolumn_name; UR = Update_rule; DR = Delete_rule; Pk = Pk_ name; FK = Fk_ name
Error Conditions
table_qualifier is a blank string
pKey_table_name is a blank string
fKey_table_name is a blank string
psp_groups
Returns the list of groups and the corresponding information from the current database or the specified database.
Syntax
call psp_groups(['database_qualifier'], ['group_name'])
Arguments
 
Returned Result Set
 
Examples
Assume that the Demodata sample database has two groups defined: DevGrp1 and DevGrp2.
call psp_groups(,)
Result Set
============ 
call psp_groups('Demodata', 'D%')
Result Set
Error Conditions
database_qualifier is a blank string
group_name is a blank string
psp_help_sp
Returns the definition text of a given stored procedure from the current database or the specified database.
Syntax
call psp_help_sp('[database_qualifier'], 'procedure_name')
Arguments
 
Returned Result Set
 
Examples
Assume that the DEMODATA sample database contains the following stored procedure saved as “Myproc.”
Create procedure Myproc(:a integer, OUT :b integer) as
Begin
Set :a = :a + 10;
Set :b = :a;
End
The following statement prints the definition text for stored procedure “Myproc” in the current database.
call psp_help_sp(, 'Myproc')
Result Set
============ 
Assume that a database named “wsrde” contains the following stored procedure saved as “Myproc1.”
Create procedure Myproc1(:a integer) returns (name char(20))
as
Begin
Select name from employee where Id =:a;
End
The following statement prints the definition text for stored procedure “Myproc1” in database “wsrde.”
call psp_help_sp('wsrde', 'Myproc1')
Result Set
Error Conditions
database_qualifier is a blank string or null
procedure_name is a blank string
psp_help_trigger
Returns the definition text of a trigger from the current database or the specified database.
Syntax
call psp_help_trigger (['database_qualifier'], 'trigger_name')
Arguments
 
Returned Result Set
 
Examples
The following statement prints the definition of the 'MyInsert' trigger:
CREATE TABLE A
(
col1 INTEGER,
col2 CHAR(255)
)
 
CREATE TABLE B
 
(
col1 INTEGER,
col2 CHAR(255)
)
 
CREATE TRIGGER MyInsert
AFTER INSERT ON A
FOR EACH ROW
INSERT INTO B VALUES
(NEW.col1, NEW.col2)
 
call psp_help_trigger(,'MyIns%')
Result Set
Error Conditions
database_qualifier is a blank string
trigger_name is a blank string
psp_help_udf
Returns the text of a given user-defined function (UDF) from the current database or the specified database.
Syntax
call psp_help_udf (['database_qualifier'], 'udf_name')
Arguments
 
Returned Result Set
 
Examples
call psp_help_udf(, 'Myfunction')
Result Set
============ 
call psp_help_udf('mydbase', 'Get%')
Result Set
Error Conditions
database_qualifier is a blank string
udf_name is null
udf_name is a blank string
psp_help_view
Returns the definition text of a view, from the current database or the specified database.
Syntax
call psp_help_view(['database_qualifier'], 'view_name')
Arguments
 
Returned Result Set
 
Example
Assume that the following view exists for the DEMODATA sample database:
CREATE VIEW vw_Person (lastn,firstn,phone) AS
SELECT Last_Name, First_Name, Phone
FROM Person
The following statement returns the definition text for view “vw_Person” in the DEMODATA database.
call psp_help_view(,'vw_Person')
or
call psp_help_view(,'vw_%')
Result Set
Error Conditions
database_qualifier is a blank string
view_name is null
view_name is a blank string
psp_indexes
Returns the list of indexes defined for the specified table. For each index, it also lists the index properties as persisted in the X$Index table.
Syntax
call psp_indexes(['table_qualifier'], ['table_name'])
Arguments
 
Returned Result Set
 
Example
call psp_indexes(,)
Result Set
Legend: Qual = Table_ qualifier; TO = Table_owner; TN = Table_name; IN = Index_name; IT = Index_type; CN = Column_name; Opos = Ordinal_position; Dup = Duplicates_allowed; UP = Updatable; Case = Case_ sensitive; A/D = Asc_desc; NI = Named_index
============ 
call psp_indexes('demodata', 'Dep%')
Result Set
Legend: Qual = Table_ qualifier; TO = Table_owner; TN = Table_name; IN = Index_name; IT = Index_type; CN = Column_name; Opos = Ordinal_position; Dup = Duplicates_allowed; UP = Updatable; Case = Case_ sensitive; A/D = Asc_desc; NI = Named_index
Error Conditions
database_qualifier is a blank string
table_name is a blank string
psp_pkeys
Returns the primary key information for the specified table, from the current database or the database specified.
Syntax
call psp_pkeys(['pkey_table_qualifier']'table_name')
Arguments
 
Returned Result Set
 
Examples
The following statement returns the information about the primary key defined on the 'pkeytest1' table:
CREATE TABLE pkeytest1
(
col1 int NOT NULL,
col2 int NOT NULL,
col3 VARCHAR(20) NOT NULL,
PRIMARY KEY(col1, col2),
UNIQUE(col3)
)
 
call psp_pkeys(,'pkeytest1')
Result Set
Error Conditions
pkey_table_qualifier is a blank string
table_name is a blank string
psp_procedure_rights
Returns the list of procedure rights and corresponding information for the specified stored procedure, from the current database or the specified database. The stored procedure can be a trusted or a non-trusted one. See Trusted and Non-trusted Objects.
Syntax
call psp_procedure_rights(['database_qualifier'], ['procedure_name'], ['user_name'])
Arguments
Returned Result Set
Examples
Assume that the following permissions exist for the DEMODATA sample database:
GRANT EXECUTE ON PROCEDURE Dept1_Proc TO John
GRANT ALTER ON PROCEDURE Dept1_Proc TO Mary
GRANT ALTER ON PROCEDURE Dept1_Proc TO John
GRANT EXECUTE ON PROCEDURE Proc2 TO Mary
GRANT ALTER ON PROCEDURE Proc2 TO Mary
GRANT ALTER ON PROCEDURE MyProc TO Mary
The following statement prints the permissions on the “Dept1_Proc” stored procedure for user “John.”
call psp_procedure_rights(,'Dept1_Proc', 'John')
Result Set
The following statement prints the permissions on the “Proc2” stored procedure for user “Mary.”
call psp_procedure_rights('demodata', '%Pr%', 'M%')
Result Set
Error Conditions
database_qualifier is a blank string
procedure_name is a blank string
user_name is a blank string
psp_rename
Changes the name of a COLUMN, INDEX, FUNCTION, PROCEDURE, TABLE, TRIGGER or VIEW in the database to which your machine is currently connected.
Syntax
call psp_rename('object_name','new_name','object_type')
Arguments
 
Example
The following statement renames stored procedure “checkstatus” to “eligibility” in the current database.
call psp_rename('checkstatus', 'eligibility', 'PROCEDURE')
Error Conditions
All errors returned from psp_rename use status code -5099. See -5099: Error condition pertaining to psp_rename in Status Codes and Messages.
psp_stored_procedures
Returns the list of stored procedures and their corresponding information from the current database or the specified database.
Syntax
call psp_stored_procedures(['database_qualifier'], ['procedure_name'], ['procedure_type'])
Arguments
 
'SP' returns the stored procedures
'SSP' returns the system stored procedures (this type is currently not supported)
*Note: System stored procedures are defined in the internal PERVASIVESYSDB database, which does not display in Pervasive PSQL Control Center.
Returned Result Set
 
Examples
Assume that the current database, "mydbase," contains two stored procedures: "myproc1" and "myproc2." The following statement lists the information about them.
Call psp_stored_procedures(, ,)
Result Set
1The complete column name includes “procedure_” prepended to this name: Procedure_qualifier, procedure_owner, and so forth.
============ 
The following statement lists the information about the stored procedures in the PERVASIVESYSDB internal database.
call psp_stored_procedures('PERVASIVESYSDB', ’psp_u%’, 'SP')
Result Set
1The complete column name includes “procedure_” prepended to this name: Procedure_qualifier, procedure_owner, and so forth.
Error Conditions
database_qualifier is a blank string
table_name is a blank string
procedure_type is a blank string
procedure_type is a value other than SP, SSP, or null
psp_tables
Returns a list of tables along with their corresponding information, from the current database or the specified database.
Syntax
call psp_tables(['database_qualifier'], ['table_name'], ['table_type'])
Arguments
 
'User table' returns only the user tables
'System table' returns all the system tables
Returned Result Set
 
System table - if the table is a system table
User table - if the table has been created by any user
Examples
call psp_tables(,,)
Result Set
============ 
call psp_tables(, , 'user table')
Result Set
============ 
call psp_tables(, , 'system table')
Result Set
Error Conditions
database_qualifier is a blank string
table_name is a blank string
table_type is a blank string
table_type is something other than 'system table,' 'user table,' or null
psp_table_rights
Returns the list of table rights and corresponding information for the specified table, from the current database or the specified database.
Syntax
call psp_table_rights(['database_qualifier'], ['table_name'], ['user_name'])
Arguments
 
Returned Result Set
 
Examples
Assume that the following permissions exist for the DEMODATA sample database.
GRANT SELECT ON Dept TO John
GRANT ALTER ON Dept TO John
GRANT DELETE ON Dept TO John
GRANT SELECT ON Class TO Mary
GRANT ALTER ON Class TO Mary
The following statement prints the table permissions on the “Dept” table for user “John” in the current database (DEMODATA).
call psp_table_rights(,'Dept', 'John')
Result Set
============ 
Assume that user “Mary” is logged on the database. The following statement prints the table permissions on the “Class” table in the DEMODATA database for the current user (Mary).
call psp_table_rights('demodata', 'cl%', )
Result Set
Error Conditions
database_qualifier is a blank string
table_name is a blank string
user_name is a blank string
psp_triggers
Returns the list of triggers and their corresponding information from the current database or the specified database.
Syntax
call psp_triggers(['database_qualifier'], ['table_name'])
Arguments
 
Returned Result Set
 
Examples
Assume that the current database is "mydbase." The following statement returns the list of triggers defined in the database:
CREATE TABLE A
(
col1 INTEGER,
col2 CHAR(255)
) ;
 
CREATE TABLE B
(
col1 INTEGER,
col2 CHAR(255)
) ;
 
CREATE TRIGGER Insert
AFTER INSERT ON A
FOR EACH ROW
INSERT INTO B VALUES
(NEW.col1, NEW.col2);
 
call psp_triggers(,)
Result Set
Error Conditions
database_qualifier is a blank string
table_name is a blank string
psp_udfs
Returns the list of user-defined functions (UDF) and their corresponding information from the current database or the specified database.
Syntax
call psp_udfs(['database_qualifier'], ['udf_name'])
Arguments
 
Returned Result Set
 
Examples
Assume that the current database, "mydbase," has two user-defined functions: "calcinterest" and "factorial."
call psp_udfs(, )
Result Set
Error Conditions
database_qualifier is a blank string
udf_name is a blank string
psp_users
Returns the list of users and the corresponding information from the current database or the specified database.
Syntax
call psp_users(['database_qualifier'], ['group_name'], ['user_name'])
Arguments
 
Returned Result Set
 
Examples
Assume that current database, "mydbase," has users "John," "Mary," and "Michael," and groups "DevGrp" and "DevGrp1."
call psp_users(, , )
Result Set
============ 
call psp_users(, 'Devgrp', )
Result Set
Error Conditions
database_qualifier is a blank string
user_name is null
group_name is a blank string
psp_view_rights
Returns the list of list of view rights and corresponding information for the specified view, from the current database or the specified database. The view can be a trusted or a non-trusted one. See See Trusted and Non-trusted Objects.
Psp_view_rights applies only to a database using V2 metadata.
Syntax
call psp_view_rights(['database_qualifier'], ['view_name'], ['user_name'])
Arguments
Returned Result Set
Examples
Assume that the following permissions exist for the DEMODATA sample database:
GRANT SELECT ON VIEW vw_Dept TO John
GRANT ALTER ON VIEW vw_Dept TO John
GRANT DELETE ON VIEW vw_Dept TO John
GRANT SELECT ON VIEW vw_Class TO Mary
GRANT ALTER ON VIEW vw_Class TO Mary
GRANT SELECT ON VIEW vw_Class TO Prakesh
The following statement prints the view permissions on the “vw_Dept” view for user “John.”
call psp_view_rights(,'vw_Dept', 'John')
Result Set
============ 
Assume that user “Mary” is logged on the database. The following statement prints the view permissions on all views in the sample database DEMODATA for the current user (Mary).
call psp_view_rights('demodata', , )
Result Set
============ 
The following statement prints the view permissions on the “vw_Class” view for user “Mary.”
call psp_view_rights('demodata', 'vw_C%', 'Mary')
Result Set
Error Conditions
database_qualifier is a blank string
view_name is a blank string
user_name is a blank string
psp_views
Returns the list of views along with their corresponding information, from the current database or from the database specified.
Syntax
call psp_views(['database_qualifier'], ['view_name'])
Arguments
 
Returned Result Set
 
Examples
Assume that the following view exists for a V2 metadata database named DEMODATA2.
CREATE VIEW vw_Person (lastn,firstn,phone) WITH EXECUTE AS ‘Master’ AS
SELECT Last_Name, First_Name,Phone FROM Person;
The following statement prints the list of views in the current database, which is DEMODATA2.
call psp_views(, ,)
Result Set
============ 
The following statement prints the view information for the “vw_Person” view in the DEMODATA database.
call psp_views('demodata', 'vw_P%')
Result Set
Error Conditions
database_qualifier is a blank string
view_name is a blank string