Home > Back-end >  in PostgreSQL how to write Random
in PostgreSQL how to write Random

Time:09-07

I'm converting oracle to PostgreSQL while converting i'm getting error like ERROR: syntax error at or near "W_SL" error please help me to solve this error.

W_SL := random.string('x', 35);

CodePudding user response:

In order to generate random string you'll need to create a function in your postgresql. For example:

CREATE OR REPLACE FUNCTION random_string_pavel(int)
RETURNS text
AS $$ 
  SELECT array_to_string(
    ARRAY (
      SELECT substring(
        '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 
        FROM (random() *36)::int FOR 1)
      FROM generate_series(1, $1) ), '' ) 
$$ LANGUAGE sql;

Here's more: https://www.simononsoftware.com/random-string-in-postgresql/

  • Related