I have a very simple PL/pgSQL script:
declare x varchar(100);
When I run it I get a message:
[WARNING ] declare x varchar(100)
ERROR: syntax error at or near "varchar"
LINE 1: declare x varchar(100)
^
I really don't understand what is wrong with this.
PostgreSQL is a procedural programming language. PL/pgSQL was designed to create user-defined functions, stored procedures, and triggers, inherit all user-defined functions, and types, and much more. Getting started with PostgreSQL : First We'll learn how to create a single table using basic PLSQL commands.
PL/pgSQL (Procedural Language/PostgreSQL) is a procedural programming language supported by the PostgreSQL ORDBMS.
Another way to declare a PL/pgSQL function is with RETURNS TABLE , for example: CREATE FUNCTION extended_sales(p_itemno int) RETURNS TABLE(quantity int, total numeric) AS $$ BEGIN RETURN QUERY SELECT s. quantity, s.
you can use procedural statements only inside function body in PostgreSQL.
CREATE OR REPLACE FUNCTION foo()
RETURNS int AS
$$ -- here start procedural part
DECLARE x int;
BEGIN
x := 10;
RETURN x;
END;
$$ -- here finish procedural part
LANGUAGE plpgsql; -- language specification
or in temporary function (anonymous block)
DO $$
DECLARE x int;
BEGIN
x := 10;
RAISE NOTICE '>>>%<<<', x;
END;
$$;
isn't possible to use procedural statements as SQL statements like T-SQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With