#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    \timing in PL/pgSQL language in SQL file


    Hi, I know how timing work in postgresql prompt, how I do is to type \timing.

    However, I have created a sql file that is based on PL/pgSQL language, for example, the sql file looks like the following,

    CREATE OR REPLACE FUNCTION make_plpgsql()
    RETURNS VOID
    LANGUAGE SQL
    AS $$
    CREATE LANGUAGE plpgsql;
    $$;

    for loop on some tables

    \timing <----------------------- gives me error
    for loop on some tables...
    \timing

    $$LANGUAGE plpgsql;



    The error is like the following,

    psql:test.sql:78: ERROR: syntax error at or near "\"
    LINE 39: \timing
    ^

    How do I make timing work in PL/pgSQL language in SQL file? Thank you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,784
    Rep Power
    348
    Originally Posted by Kalimoor
    Hw do I make timing work in PL/pgSQL language in SQL file? Thank you.
    You can't \timing is a psql (only) command and does not work inside a function.

    You need to do the timing when using the function in psql, basically something like this:

    Code:
    postgres=> \timing
    Timing is on
    postgres=>select make_plpgsql();
    ..
    ..
    Time: xx ms
    postgres=>

IMN logo majestic logo threadwatch logo seochat tools logo