1

I want to create a table random_record that takes in the same columns as another table simulated_records; one of the columns is grade. But I keep getting this error:

ERROR: "random_record.grade" is not a known variable
LINE 45: random_record.grade = c_grade;
^

********** Error **********

ERROR: "random_record.grade" is not a known variable
SQL state: 42601
Character: 1635

FOR i IN 1..6 LOOP

    CREATE TABLE random_record AS 
    SELECT ....

    IF random_record.grade = '-' THEN

    .....

    END IF;


....

END LOOP;

I am not sure if I am properly creating the table.

3
  • refer this link: postgresql.org/docs/9.2/static/sql-createtableas.html Commented Nov 2, 2016 at 3:48
  • I think you want a CASE ... WHEN as part of the CREATE TABLE AS ... SELECT ... Commented Nov 2, 2016 at 5:05
  • @CraigRinger Thanks, this helped me figured it out. Commented Nov 2, 2016 at 15:28

1 Answer 1

1
  • you created table well, but the table is not a variable, so line

    IF random_record.grade = '-' THEN 
    

    has not any sense. It is hard to identify, what you want, because using table in this context has not any value.

  • creating in table in cycle has another issue - the statement CREATE TABLE will work only in first loop of cycle. Second loop has to fail, because table exists already.

It is hard help, because this code is messy - it is mixing variables, tables together, and it is not possible. Every object has own dimension, own access methods, and these mechanisms are different.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.