I have a problem with my procedure. We have 2 tables : companies and typeofcompanies. Companies have 3 columns ("companyid","companyname","typeofcompany") , typeofcompanies have 2 columns ("typeofcompanyId", "typeofcompany");
This is my code for insert values into companies:
CREATE OR REPLACE FUNCTION insert_to_companies(c_name VARCHAR(255),toc INTEGER)
RETURNS VOID AS $$
DECLARE i integer;
BEGIN
FOR i IN SELECT "typeofcompanyId" FROM typeofcompanies LOOP
IF toc = i THEN insert into public.companies(companyname, typeofcompany) VALUES (c_name,toc);
END IF;
END LOOP;
IF(SELECT companyname FROM companies WHERE companyname = c_name) = NULL THEN insert into public.typeofcompanies(typeofcompany) VALUES (toc);
INSERT into public.companies(companyname,typeofcompany) VALUES (c_name,toc);
END IF;
END;
$$ LANGUAGE plpgsql VOLATILE;
So if we haven't typeofcompany we should create it. But when i SELECT insert_to_companies("1",5); i take ERROR: column "1" does not exist. So i think it's very easier problem, but i spent more than 3 hour and can't find problem. Please, i need help....
code for creating table with liquibase
companies:
<databaseChangeLog xmlns = "http://www.liquibase.org/xml/ns/dbchangelog/1.9" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
<changeSet id="1" author="tiurinvalery@gmail.com" runOnChange="true" >
<createTable tableName ="companies">
<column autoIncrement = "true" name = "companyid" type ="BIGINT">
<constraints primaryKey ="true"></constraints>
</column>
<column name="companyname" type="VARCHAR(255)">
</column>
<column name="typeofcompany" type="INTEGER">
</column>
</createTable>
</changeSet>
</databaseChangeLog>
For type of companies:
<databaseChangeLog xmlns = "http://www.liquibase.org/xml/ns/dbchangelog/1.9" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd" >
<changeSet id="5" author="tiurinvalery@gmail.com" runOnChange="true" >
<createTable tableName ="typeofcompanies">
<column autoIncrement = "true" name = "typeofcompanyId" type ="BIGINT">
<constraints nullable="false" primaryKey="true"></constraints>
</column>
<column name = "typeofcompany" type="VARCHAR(255)">
<constraints nullable="false"></constraints>
</column>
</createTable>
</changeSet>
</databaseChangeLog>