建立函数: CREATE OR REPLACE FUNCTION enumtest(anyenum) RETURNS text AS $$ ::text; $$ LANGUAGE SQL; 建立enum: pgsql=# CREATE TYPE ecolor AS ENUM ('white','green','blue'); CREATE TYPE pgsql=# pgsql=# CREATE TYPE esize AS ENUM ('small','middle','big'); CREATE
执行前: 最终代码: CREATE OR REPLACE FUNCTION "ap"."iter_drop_table_bak"() RETURNS "pg_catalog"."void" AS $BODY$ DECLARE row_tag VARCHAR(200); BEGIN FOR row_tag IN ( select tablename from pg_tables where schemaname='ap' and
例子1,不带returns : [postgres@cnrd56 bin]$ ./psql psql () Type "help" for help. postgres=# CREATE FUNCTION sales_tax(subtotal real, OUT tax real) AS $$ postgres$# BEGIN postgres$# tax := subtotal * 0.06; postgres$# END; postgres$# $$ LANGUAGE plpgsq
CREATE OR REPLACE FUNCTION "json_object_del_path"( "json" json, "key_path" TEXT[] ) RETURNS json LANGUAGE sql IMMUTABLE STRICT AS $function$ SELECT CASE WHEN ("json" -> "key_path"[l] ) IS NULL THEN &quo
-- sum() over(partition by ... order by ...)SELECT len/sum(len)over(partition by road_id) param from rs; -- min() over(partition by ... order by ...)SELECT min(len)over(partition by road_id) param from rs; -- max() over(partition by ... order by ...)
CREATE OR REPLACE FUNCTION test1(id INTEGER,id1 INTEGER) RETURNS INTEGER LANGUAGE plpgsql AS $$ declare count integer; begin count = (select array_position(string,'hehe19') from public.sal_emp1 where name = 'Bill31'); raise notice 'this is raise demo
pgsql function 系列之一:返回结果集--------------------------------------------------------------------------------我们在编写postgresql数据库的函数(或称为存储过程)时,时常会遇到需要返回一个结果集的情况,如何返回一个结果集,返回一个结果集有多少种方式,以及如何选择一个合适的方式返回结果集,这是一个需要仔细考虑的问题.本文仅简单的罗列出各种返回结果集的方式并试图分析他们的特点,而采用何种方式则
pgsql 常用的命令:1. 创建数据库create database name with owner username; 2. 创建用户create role with createdb ;create user user_name; 3. 修改密码alter user user_name with password 'new password'; 查询当前db中所有表的信息:"select * from pg_tables" —— 得到当前db中所有表的信息(这里pg_tables
http://www.postgresonline.com/journal/archives/239-The-wonders-of-Any-Element.html 定义函数 pgsql=# CREATE OR REPLACE FUNCTION diff_inc(IN anyelement, IN anyelement pgsql(# , OUT diff integer, OUT f_val anyelement, OUT l_val anyelement) pgsql-# RETURNS r
http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 如果一个PL/pgSQL函数声明了输出参数,输出参数被赋予$n名称和可选的别名,和正常输入参数的作法一样.输出参数是一个从NULL开始的变量:它将被在函数的执行过程中被赋值.此参数的最后的值就是函数的返回值.例如,the sales-tax 例子可以这样实现: 例子: CREATE FUNCTION sales_tax(subtotal real, OUT ta