0

I am trying to make a function which calls a specific data from the table but why it's showing column doesn't exist even tho its on database .

CREATE FUNCTION public."updateDB"(IN userid bigint DEFAULT 00000, OUT uinfo json, IN clname text DEFAULT info)
RETURNS json
LANGUAGE 'plpgsql'
AS $BODY$
BEGIN
    SELECT clname into uinfo 
    FROM public.users 
    WHERE uid = userid;
END;
$BODY$;

but when i try to call it , it shows this error here i tried to make info default so this error occurs . If i don't make anything default and run the function from code , it shows that error again.

Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
Axel
  • 23
  • 1
  • 8

1 Answers1

1

You need quote your text otherwise postgres think you are referring to a column

IN clname text DEFAULT 'info'
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
  • i tried that but if i run `select selectDB("info",23435353335)` from code , this error occurs `ERROR: column "info" does not exist LINE 1: select selectDB(info,23435353335) ^ SQL state: 42703 Character: 17` – Axel Jul 23 '18 at 13:49
  • `'info'` is a string value `"info"` is a column name. Try `selectDB('info',23435353335)`. But I dont think that will give you what you want. that only will return `'info'` as result – Juan Carlos Oropeza Jul 23 '18 at 14:12
  • btw your function is called `updteDB` not `selectDB` – Juan Carlos Oropeza Jul 23 '18 at 14:13