post by despigares on Apr 29, 2021

Hello,

I have installed the grocery crud version for codeigniter 4. I use the postgresql database and I have configured codeigniter 4 to connect to postgresql.

Apparently the connection works correctly, but when I try to access the data it seems that it is using the mysql syntax, for example I get this error:
pg_query (): Query failed: ERROR: syntax error at or near “FROM” LINE 1: SHOW COLUMNS FROM

It’s using the postgres driver (pg_query) but the model is not correct, ‘Show columns’ is not correct for postgres.

Some other grocery crud model file for postgres is needed?

Thank you in advance.

9 months later

post by gatoman on Feb 3, 2022

what you said is correct, postgreSQL does not support that sintaxis (‘SHOW COLUMNS’), first of all I ‘ve replace that line (439) with this query
"SELECT x.column_name AS “Field”, x.data_type AS type,x.is_nullable AS “Null”,x.column_default as Default,CASE WHEN x.column_default LIKE ‘nextval(%’ THEN ‘auto_increment’ ELSE ‘’ END AS extra,CASE WHEN(select count(*) from information_schema.table_constraints tco join information_schema.key_column_usage kcu on kcu.constraint_name = tco.constraint_name and kcu.constraint_schema = tco.constraint_schema and kcu.constraint_name = tco.constraint_name where tco.constraint_type = ‘PRIMARY KEY’ AND x.column_name =kcu.column_name AND kcu.table_schema=’{$this->table_schema}’ and kcu.table_name=‘{$this->table_name}’ )>0 THEN ‘PRI’ ELSE NULL END AS “Key” FROM information_schema.columns x WHERE x.table_schema = ‘{$this->table_schema}’ AND x.table_name = ‘{$this->table_name}’;;"

This enable the list for the get_field_types_basic_table() method.
try replacing it.

1 / 2
Apr 2021