Tag Info

New answers tagged

7

A LANGUAGE sql function must be a complete SQL statement (or more than one). Yours is just an expression. Just prepend SELECT, like you would when running it stand-alone. $BODY$ SELECT (SELECT ... The reason it complains at the + is that, surprisingly, it's legal to parenthesise a top-level query. This, for example, is a valid query: regress=> ...


0

A very basic example would be to get the AVG and STDEV of the range of numbers and then exclude any that were more than 1 Standard Deviation from that average. You then take the average of the new range. This is quite a basic bit of code (don't forget the CAST to a DECIMAL) which you can expand upon to make it more suitable to your needs. CREATE TABLE ...


3

It will be available in 9.5. Here is actual git commit https://github.com/postgres/postgres/commit/08309aaf74ee879699165ec8a2d53e56f2d2e947 Discussion on pg hackers http://postgresql.nabble.com/CREATE-IF-NOT-EXISTS-INDEX-td5821173.html


2

I highly recommend this alternative approach to get an IMMUTABLE unaccent() function: CREATE OR REPLACE FUNCTION f_unaccent(text) RETURNS text AS $func$ SELECT unaccent('unaccent', $1) $func$ LANGUAGE sql IMMUTABLE SET search_path = public, pg_temp; Use that function for the expression index (and in all queries). Detailed explanation in this related ...


1

WITH parametros AS ( SELECT '2015-03-06'::timestamp AS fecha_desde -- provide parameters here , '2015-03-12'::timestamp AS fecha_hasta ) SELECT tropa, max(fecha) AS fecha, sum(cantidad) AS sum_cantidad , sum(sum(cantidad)) OVER (PARTITION BY tropa ORDER BY max(fecha)) AS saldo FROM movimiento_stock, ...



Top 50 recent answers are included