Re: Totally new, two main problems.

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: wepwep <gerrtunk(at)gmail(dot)com>
Subject: Re: Totally new, two main problems.
Date: 2011-03-29 23:33:01
Message-ID: 201103291633.02201.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday, March 29, 2011 2:20:33 pm wepwep wrote:
> Im learning pg sql and psql in general. Im using console psql in windows.
> For now, i installed it correctly and execute it, ok.
>
> My first problem is that i dont know how to execute a pgsql script when im
> in the psql program.
> CREATE FUNCTION sales_tax(subtotal real) RETURNS real AS $$
> BEGIN
> RETURN subtotal * 0.06;
> END;
> $$ LANGUAGE plpgsql;
>
>
> This is in c:/2tri/scr.sql. How i can execute that?

From in psql> \i c:/2tri/scr.sql will load the function into the database,
assuming the user you are logged in has appropriate permissions. FYI I would use
the form CREATE OR REPLACE FUNCTION. This allows you change an existing function
without dropping it.

Then do :
select sales_tax(150.24);

>
> Also my other problem is with pgsql syntax. How i can print a text to the
> console for checking, debugign, etc, i dont see anything to do that.

See here:
http://www.postgresql.org/docs/9.0/interactive/plpgsql-errors-and-messages.html

If you are using 9.0+ you might also want to check out DO:
http://www.postgresql.org/docs/9.0/interactive/sql-do.html

>
> --
> View this message in context:
> http://postgresql.1045698.n5.nabble.com/Totally-new-two-main-problems-tp42
> 70202p4270202.html Sent from the PostgreSQL - general mailing list archive
> at Nabble.com.

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GÜNDÜZ 2011-03-30 01:31:41 Re: RPM for ODBC driver
Previous Message Adrian Klaver 2011-03-29 23:24:58 Re: Date conversion using day of week