Function PostgreSQL 9.2
От
drum.lucas@gmail.com
Тема
Function PostgreSQL 9.2
Дата
Msg-id
CAE_gQfWbZBSYwa6vBfVOgZH9c4i9OS7fNqahhFXgcuAu29tE_g@mail.gmail.com
Список
Дерево обсуждения
Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 Adrian Klaver <adrian.klaver@aklaver.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 Adrian Klaver <adrian.klaver@aklaver.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 John R Pierce <pierce@hogranch.com>
Re: Function PostgreSQL 9.2 Adrian Klaver <adrian.klaver@aklaver.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 John R Pierce <pierce@hogranch.com>
Re: Function PostgreSQL 9.2 Adrian Klaver <adrian.klaver@aklaver.com>
Re: Function PostgreSQL 9.2 Karsten Hilbert <Karsten.Hilbert@gmx.net>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 Melvin Davidson <melvin6925@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 Adrian Klaver <adrian.klaver@aklaver.com>
Re: Function PostgreSQL 9.2 Adrian Klaver <adrian.klaver@aklaver.com>
Re: Function PostgreSQL 9.2 Melvin Davidson <melvin6925@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 Melvin Davidson <melvin6925@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 Berend Tober <btober@computer.org>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 Berend Tober <btober@computer.org>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 John R Pierce <pierce@hogranch.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 Alban Hertroys <haramrae@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 Berend Tober <btober@computer.org>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 Berend Tober <btober@computer.org>
Re: Function PostgreSQL 9.2 Lucas Possamai <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 Melvin Davidson <melvin6925@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 Berend Tober <btober@computer.org>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 "Mike Sofen" <msofen@runbox.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Re: Function PostgreSQL 9.2 "Mike Sofen" <msofen@runbox.com>
Re: Function PostgreSQL 9.2 "David G. Johnston" <david.g.johnston@gmail.com>
Re: Function PostgreSQL 9.2 "drum.lucas@gmail.com" <drum.lucas@gmail.com>
Hi all,
I've got two tables:
- users
- companies
I'm trying to create a function that:
- if users.code is empty, it gives a default value
- And the increment_client_code in company should auto increment for the next client code
What I've done so far:
DROP FUNCTION IF EXISTS client_code_increment_count();
CREATE OR REPLACE FUNCTION "public"."client_code_increment_count" () RETURNS TABLE("code" INT) AS
$BODY$
SELECT MAX(CAST(users.code AS INT)) FROM users WHERE users.code ~ '^\d+$' AND company_id = 2
$BODY$
LANGUAGE sql;
SELECT * FROM "client_code_increment_count"();
CREATE OR REPLACE FUNCTION "public"."auto_generate_client_code_if_empty" () RETURNS "trigger"
VOLATILE
AS $dbvis$
BEGIN
END;
$dbvis$ LANGUAGE plpgsql;
CREATE TRIGGER "increment_client_code"
BEFORE INSERT OR UPDATE ON users
FOR EACH ROW
EXECUTE PROCEDURE "auto_generate_client_code_if_empty"();
But still can't do that works.. What Am I missing?
Cheers
В списке pgsql-general по дате отправления