Herramientas de usuario

Herramientas del sitio


informatica:base_de_datos:postgresql:postgresql_store

¡Esta es una revisión vieja del documento!


PostgreSQL Store

Se puede crear un store de dos formas, usando SQL o usando PL/PgSQL

Ejemplo de bloque de codigo con DO

DO $$
DECLARE
    -- Declare variables with initial values
    counter INTEGER := 1;
    first_name VARCHAR(50) DEFAULT 'John';
    payment NUMERIC(11, 2) = 20.5;
 
    -- Declare a constant
    user_id CONSTANT INTEGER := 10;
 
    -- Declare a variable based on a table column's type
    film_title film.title%TYPE; 
BEGIN
    -- Assign a value from a query result
    SELECT title INTO film_title FROM film WHERE film_id = user_id;
 
    -- Output the variable values (for demonstration purposes, like in pgAdmin's Messages window)
    RAISE NOTICE '% % % has been paid % USD, Film title: %', counter, first_name, payment, film_title;
 
    -- The following line would cause an error because user_id is a CONSTANT
    -- user_id := 12; 
END $$;
informatica/base_de_datos/postgresql/postgresql_store.1769399284.txt.gz · Última modificación: 2026/01/26 03:48 por admin